From c989991515f264674ff8fea66c3b6405f424345d Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Tue, 9 Aug 2016 02:16:39 +1000 Subject: [PATCH] Added coding-style.md --- doc/coding-style.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 doc/coding-style.md diff --git a/doc/coding-style.md b/doc/coding-style.md new file mode 100644 index 00000000..d8cf7705 --- /dev/null +++ b/doc/coding-style.md @@ -0,0 +1,33 @@ +Coding Style +=============== + +In order to maintain a consistent style across the codebase, the following coding style has been adopted: + +- Function names use PascalCase (func SomeFunc()). +- Function names using acronyms are capitilised (func SendHTTPRequest()). +- Variable names use CamelCase (var someVar()). +- Coding style uses gofmt. +- Const variables are capitilised. +- In line with gofmt, for loops and if statements don't require paranthesis. + +Block style example: +```go +func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error) { + result := strings.ToUpper(method) + + if result != "POST" && result != "GET" && result != "DELETE" { + return "", errors.New("Invalid HTTP method specified.") + } + + req, err := http.NewRequest(method, path, body) + + if err != nil { + return "", err + } + + for k, v := range headers { + req.Header.Add(k, v) + } + ... +} +```