In accordance with the POSIX standard, the last line of a file should be empty - that is, the file should have a new-line character appended to the last line.
Why?
The POSIX standard is intended to provide compatibility with many command line tools, such as `cat`.
If you use cat on a file that does not have th final new-line character and you haven’t configured your shell to allow for that, you may find your prompt appearing on the same line as the last line of the output of cat.
file1
1File1Line12File1Line2
$ cat file1 file2
File1Line1
File1Line2$
If you use cat on two files and the first one does not have the final new-line character, the first line of the second file will be appended to the last line of the first file.
Swapping the order of the files so the file with the final new-line character is first will output each line on it’s own, but your prompt may still end up on the same line as the last line of the output.
Packages can be divided in to three types, standard library, our own packages, and third party packages.
Imports should be grouped accordingly, with the standard library packages first, followed by packages starting with
github.com/cirruscomms/ and then third party packages.
Package names should be camelCase, with the exception of _test packages, which should just be camelCase package names
with the _test suffix appended to them.
Examples
packages.go
1packagesimple// okay2packagesimpleBrands// okay3packagesimpleBrands_test// okay45packagesimple_brands// not okay6packagesimplebrands// not okay
Naming Types
ProposedCF02215
Naming Constants
ProposedCF02220
Naming Variables
ProposedCF02225
Naming Interfaces
ProposedCF02230
Naming Mock Structs
ProposedCF02235
Naming Functions
ProposedCF02240
Naming Methods
ProposedCF02245
Initialisms - Never Mixed Case
ProposedCF02250
Initialisms should be written either in all upper or all lower case, never mixed.
If the initialism is the prefix of an unexported function, method, variable, constant, or type (thing), it the initialism should be written in all lower case, otherwise it should be all uppercase.
Try to name the thing to avoid having two adjacent initialisms, but if you can’t, the rules above apply to them independently.
Examples
initialisms.go
1varnbnClient="okay"// not exported with initialism as prefix should be lower case 2varNBNClient="okay"// exported with initialism as prefix should be upper case 3varNbnClient="not okay"// exported with initialism as prefix should not be mixed case 4varmobileSIMSerial="okay"// not exported with initialisms in middle should be upper case 5varmobileSimSerial="not okay"// not exported with initialisms in middle should be not be mixed case 6 7varNBNTC4Client="okay"// exported with adjacent initialisms as prefix should have mixed case 8varnbnTC4Client="okay"// not exported with adjacent initialisms as prefix should have the first in lower and subsequent in upper case 9varnbntc4Client="not okay"// prefix, adjacent, not exported lower + lower case1011varrequestID="okay"// not exported with initialism outside the prefix should be upper case12varRequestID="okay"// exported with initialism outside the prefix should be upper case13varRequestId="no okay"// exported with initialism outside the prefix should not be mixed case14varrequestId="no okay"// not exported with initialism outside the prefix should not be mixed case15varrequestid="no okay"// not exported with initialism outside the prefix should not lower case16varRequestid="no okay"// exported with initialism outside the prefix should not lower case
Keep them on a single line unless the line exceeds 120 characters, at which point they should be wrapped between 80 and 120 characters, preferably with one parameter per line.
Examples
signatures.go
1// MustRepeatSomething needs a GoDoc comment 2funcMustRepeatSomething(ctxcontext.Context,repeatsint){ 3// ... 4} 5 6// MustRepeatManyThings needs a GoDoc comment 7funcMustRepeatManyThings( 8ctxcontext.Context, 9repeatsint,10param1map[string]string,11param2map[string]string,12param2map[string]string,13param2map[string]string,14){15// ...16}1718// RepeatManyThings needs a GoDoc comment19funcRepeatManyThings(20ctxcontext.Context,21repeatsint,22param1map[string]string,23param2map[string]string,24param2map[string]string,25param2map[string]string,26)(faulterror){27// ...28}
Functions & Methods - Named Contract Returns
NormativeCF02420