-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from dyweb/doc/add-example
[doc] Improve doc and add example Fix #67
- Loading branch information
Showing
45 changed files
with
330 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Package cast convert types safely and drop incompatible types during conversion | ||
// | ||
// it is inspired by https://github.com/spf13/cast | ||
package cast | ||
package cast // import "github.com/dyweb/gommon/cast" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Directory | ||
|
||
- [cmd/gommon](../cmd/gommon) the command line application | ||
- [cast](../cast) converter needed for config | ||
- [config](../config) config file reader | ||
- [doc](.) documentation | ||
- [errors](../errors) error wrapping and multi error | ||
- [generator](../generator) generating interface methods, render go template, protobuf etc. | ||
- [legacy](../legacy) legacy code base | ||
- [noodle](../noodle) embed static assets for go binary with .ignore file support | ||
- [playground](../playground) test library and replay issues | ||
- [requests](../requests) http util | ||
- [scripts](../scripts) test scripts | ||
- [structure](../structure) data structure | ||
- [util](../util) util packages for public use, they are too small to be top level package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Develop environment setup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Coding Style | ||
|
||
The coding style can be split into two parts, application and library, | ||
gommon is mainly a set of libraries, but it also contains a command line application with same name `gommon`. | ||
|
||
## Folder structure | ||
|
||
see [directory](directory.md) | ||
|
||
## Documentation | ||
|
||
MUST cover the following | ||
|
||
- [ ] convention, i.e. variable names, error handling etc. | ||
- [ ] internal, a basic walk through of import parts | ||
- define canonical import path in `pkg.go` https://golang.org/doc/go1.4#canonicalimports | ||
|
||
## Application | ||
|
||
### Application error handling | ||
|
||
- when using `log.Fatal`, add a `return` after it, it won't get executed, but it makes the abort logic more obvious | ||
|
||
Good | ||
|
||
````go | ||
if cfg.Port < 0 { | ||
log.Fatalf("invalid port number %d", cfg.Port) | ||
return | ||
} | ||
server.Serve(cfg.Port) | ||
```` | ||
|
||
Bad | ||
|
||
````go | ||
if cfg.Port < 0 { | ||
log.Fatalf("invalid port number %d", cfg.Port) | ||
} | ||
server.Serve(cfg.Port) | ||
```` | ||
|
||
## Library | ||
|
||
### Library error handling | ||
|
||
- DO NOT use `log.Fatal`, `panic`, always return error, if an error is added later, many application won't compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
Package log provides structured logging with fine grained control | ||
over libraries using a tree hierarchy of loggers. | ||
Conventions | ||
1. no direct use of the log package, MUST create new logger. | ||
2. library/application MUST have a library/application logger as their registry. | ||
3. every package MUST have a package level logger as child of the registry, normally defined in pkg.go | ||
4. logger is a registry and can contain children. | ||
5. instance of struct should have their own logger as children of package logger | ||
*/ | ||
package log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.