-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
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,71 @@ | ||
# go_infrastructure | ||
|
||
**用途:工具包,基于 golang 实现** | ||
|
||
## env | ||
|
||
- 目录配置 | ||
|
||
```golang | ||
var ( | ||
Dir string | ||
RunDir string | ||
LogDir string | ||
LogPath string | ||
ConfigPath string | ||
ConfigDir string | ||
Pid int | ||
Hostname string | ||
) | ||
``` | ||
|
||
## config | ||
|
||
- init some infrastructure eg: some middleware like | ||
consul (service discover) , mq , gRpc ... | ||
|
||
## log | ||
|
||
- rotate log | ||
|
||
```golang | ||
import ( | ||
"github.com/go_infrastructure/log" | ||
"github.com/go_infrastructure/env" | ||
) | ||
|
||
func init() { | ||
var Access log.Logger | ||
path, _ := filepath.Abs(env.LogDir + "/access.log") | ||
A, err = glog.NewLogger(path, "debug") | ||
env.ErrExit(err) | ||
// 通过 var Access log.Logger 设定 | ||
// 访问日志,调试日志,错误日志,... | ||
// what ever you like 😁 | ||
} | ||
//example | ||
func log() { | ||
//hanler err | ||
var err error | ||
A.Info("", err) | ||
} | ||
``` | ||
|
||
## validate | ||
|
||
- 检测 中文和可见字符 | ||
|
||
## errors | ||
|
||
- 错误处理 | ||
|
||
```golang | ||
type Error struct { | ||
Code int `json:"code"` | ||
Status int `json:"Status"` | ||
Detail string `json:"detail"` | ||
Internal string `json:"internal,omitempty"` | ||
Content interface{} `json:"content,omitempty"` | ||
} | ||
``` | ||
|