WIP Specified header & footer now included in output #6

Manually merged
sloum merged 2 commits from headers_and_footers into develop 2019-09-28 02:22:02 +00:00
Collaborator

While this is functionally complete, it needs further changes. The new functionality:

  • main() now creates a list ([]string) of files to process
  • For each file in that list, it reads and processes the files, adding any output to a variable
  • that variable is written to file or stdout as before

It's important to note that headers and footers are also processed by the construct/deconstruct functions. This is a bit more flexible, but also is less effort to add in.

This version really mashes types together, changing type fairly often when there might be more appropriate ways to handle the same type. The main issue is that I opted to use strings.Builder to concatenate processed output because I read it was the faster way. This conflicted with the already prevalent use of bytes.Buffer though.

I'll need to do some more reading and thinking before I take another go at this. If you have any advice, feel free to let me know.

While this is functionally complete, it needs further changes. The new functionality: - `main()` now creates a list ([]string) of files to process - For each file in that list, it reads and processes the files, adding any output to a variable - that variable is written to file or stdout as before It's important to note that headers and footers are also processed by the construct/deconstruct functions. This is a bit more flexible, but also is less effort to add in. This version really mashes types together, changing type fairly often when there might be more appropriate ways to handle the same type. The main issue is that I opted to use strings.Builder to concatenate processed output because I read it was the faster way. This conflicted with the already prevalent use of bytes.Buffer though. I'll need to do some more reading and thinking before I take another go at this. If you have any advice, feel free to let me know.
asdf self-assigned this 2019-09-27 01:49:21 +00:00
sloum approved these changes 2019-09-27 04:17:32 +00:00
sloum left a comment
Owner

This all looks great! I think processing the header and footer with the body like this is the right way to go (rather than formatting them separately before running it all together)

This all looks great! I think processing the header and footer with the body like this is the right way to go (rather than formatting them separately before running it all together)
@ -140,3 +140,3 @@
}
defer file.Close()
file.Write(outFile.Bytes())
file.WriteString(outFile)
Owner

This is cool. I didnt know io like this had a string method for write. It makes sense that it would... good switch!

This is cool. I didnt know io like this had a string method for write. It makes sense that it would... good switch!
Author
Collaborator

Yeah the number of different functions available in the libraries is pretty impressive. I was trying to find out about func (*file) Write and saw it two below and was like HMMMM

Yeah the number of different functions available in the libraries is pretty impressive. I was trying to find out about `func (*file) Write` and saw it two below and was like HMMMM
@ -194,2 +195,2 @@
if err != nil {
log.Fatalln("Error while reading file -", err)
//read and process files
var outFile = strings.Builder{}
Owner

I prefer strings.Builder these days (to bytes), I had been using bytes, for no particularly good reason, when I started this project.

I prefer strings.Builder these days (to bytes), I had been using bytes, for no particularly good reason, when I started this project.
Author
Collaborator

Ah great, thank you for your advice on this. It explains a fair bit!

I thought about it more and want to avoid changing types as often as it currently is, for the sake of consistency. I'll do a bit more work on this, plus some documentation, and advise when done.

Ah great, thank you for your advice on this. It explains a fair bit! I thought about it more and want to avoid changing types as often as it currently is, for the sake of consistency. I'll do a bit more work on this, plus some documentation, and advise when done.
Author
Collaborator

OK I'm pretty happy with this now. All functions that accept or return processed data now do so using a string. strings.StringBuilder is used for those string operations.

Documentation updated to include some information about using the -head and -foot flags.

OK I'm pretty happy with this now. All functions that accept or return processed data now do so using a string. strings.StringBuilder is used for those string operations. Documentation updated to include some information about using the -head and -foot flags.
Owner

Awesome! Merging in. This is great :)

Awesome! Merging in. This is great :)
sloum closed this pull request 2019-09-28 02:22:02 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sloum/gfu#6
No description provided.