コンフィギュレーション
行く-これ/これらは、
読書のためのINI設定ファイルの形式。
住所:https://github.com/Go-ini/ini
tomal
設定ファイルを読み込むための会議]形式。
住所:https://github.com/BurntSushi/toml
行く-YAML / YAML
設定ファイルを読み込むためのYAMLフォーマット。
住所:https://github.com/go-yaml/yaml
マスターでwblog / system.go・wangsongyan / wblog
https://github.com/wangsongyan/wblog/blob/master/system/system.go
type Configuration struct {
Addr string `yaml:"addr"`
}
var config *Configuration
func LoadConfig() error {
data, err := ioutil.ReadFile("conf/conf.yaml")
if err != nil {
return err
}
err = yaml.Unmarshal(data, &config)
if err != nil {
return err
}
}
func GetConfig() *Configuration {
return config
}
ジャーナル
-
https://github.com/sirupsen/logrus
Logrusが行くの言語で実装ロギングシステムで、標準ライブラリのログおよびコアAPIと完全に互換性があることは非常に安定している、囲碁言語は現在最もアクティブなログライブラリです。 -
https://github.com/uber-go/zap
速く、構造化、階層的なログデータベースのサポート。 -
https://github.com/golang/glog
ログライブラリを採点。 -
https://github.com/cihub/seelog
seelog Goは、言語のロギングシステムで、それはフィルタリングや書式設定、複雑なログ配布を通じて達成いくつかの単純な機能を提供します。
ビーゴ/ログ
ドキュメント:https://beego.me/docs/module/logs.md
例:
package util
import (
"errors"
"fmt"
"github.com/astaxie/beego/logs"
)
var Logger *logs.BeeLogger
func InitLog() error {
Logger = logs.NewLogger(10) //缓冲区的大小
Logger.SetLevel(logs.LevelDebug) // 设置日志写入缓冲区的等级:Debug级别(最低级别,所以所有log都会输入到缓冲区)
Logger.EnableFuncCallDepth(true) //显示行号
jsonConfig := fmt.Sprintf(`{"filename":"%s/log/sample.log", "daily":true,"maxdays":7,"rotate":true}`, GetCurrPath())
err := Logger.SetLogger(logs.AdapterMultiFile, jsonConfig)
if err != nil {
return errors.New("init log error:" + err.Error())
}
Logger.Async(10) //设置缓冲 chan 的大小
return nil
}
func GetCurrPath() string {
file, _ := exec.LookPath(os.Args[0])
path, _ := filepath.Abs(file)
index := strings.LastIndex(path, string(os.PathSeparator))
ret := path[:index]
return ret
}
logrus
seelog
logger, err := log.LoggerFromConfigAsFile("conf/seelog.xml")
if err != nil {
return err
}
log.ReplaceLogger(logger)
//start
seelog.Debug("something...")
プロファイル?
参照:https://astaxie.gitbooks.io/build-web-application-with-golang/zh/12.1.html
セッション
ゴー標準パッケージは現在、自分自身で達成する必要があるとのセッションのすべてのサポートを提供していません。インプリメンテーションを参照してください:https://astaxie.gitbooks.io/build-web-application-with-golang/content/zh/06.2.html
また、ビーゴフレームワークが達成された使用することができます。
go get github.com/astaxie/beego/session
参照:https://beego.me/docs/module/session.md
日付
-
https://github.com/jinzhu/nowは
今行く言語ツールセットまでの時間です。 -
https://github.com/uniplaces/carbon
時間の簡単な拡張子は、多くの有用な方法があり、インターフェースPHPカーボンライブラリです。
Eメール
-
https://github.com/go-gomail/gomail
GoMailは、電子メールを送信するための非常にシンプルかつ強力なライブラリです。 -
https://github.com/jordan-wright/email
堅牢かつ柔軟な電子メールのライブラリ。 -
https://github.com/matcornic/hermes
クリーン、応答HTML形式の電子メールテンプレートを生成します。
例:
package email
import (
"gopkg.in/gomail.v2"
"strconv"
)
//发送邮件
func SendMail(mailTo []string, subject string, body string) error {
//定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码,qq邮箱填授权码
mailConn := map[string]string{
"user": "",
"pass": "",
"host": "",
"port": "",
}
port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int
m := gomail.NewMessage()
m.SetHeader("From", mailConn["user"]) //这种方式可以添加别名
m.SetHeader("To", mailTo...) //发送给多个用户
m.SetHeader("Subject", subject) //设置邮件主题
m.SetBody("text/html", body) //设置邮件正文
d := gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"])
err := d.DialAndSend(m)
return err
}
タイマー
https://github.com/robfig/cron
参照
1、GolangとビルドWebアプリケーション
https://astaxie.gitbooks.io/build-web-application-with-golang/zh/
2、avelino /素晴らしい-GO:Aは素晴らしいゴーフレームワーク、ライブラリ、およびソフトウェアのリストをキュレーションし
ます。https: //github.com/avelino/awesome-go
3、jobbole /素晴らしいゴーCN:ゴー大全中文版资源
https://github.com/jobbole/awesome-go-cn
4、hackstoic / golang -オープンソース-projects:为互联网IT人打造的中文版素晴らしい-行く
https://github.com/hackstoic/golang-open-source-projects
5、サーチ・素晴らしい-行く
https://github.com/search?q=素晴らしい-行きます