configuração
go-este / estes
formato de arquivo de configuração INI para leitura.
Endereço: https://github.com/Go-ini/ini
Tomal
formato Conf para a leitura do arquivo de configuração.
Endereço: https://github.com/BurntSushi/toml
go-yaml / yaml
formato yaml para a leitura do arquivo de configuração.
Endereço: https://github.com/go-yaml/yaml
wblog / system.go pelo mestre · 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
}
revista
-
https://github.com/sirupsen/logrus
Logrus é um sistema de registro implementado com a linguagem Go, é totalmente compatível com o log biblioteca padrão e API núcleo é muito estável, a linguagem Go é atualmente a biblioteca logging mais ativo. -
https://github.com/uber-go/zap
rápido, estruturado, suporte de banco de dados log hierárquica. -
https://github.com/golang/glog
classificação biblioteca logging. -
https://github.com/cihub/seelog
seelog Go é um sistema de registro de linguagem, ele fornece algumas funções simples alcançados através da distribuição log complexo, filtragem e formatação.
beego / logs
Documentação: https://beego.me/docs/module/logs.md
exemplo:
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...")
Perfis?
Veja: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/12.1.html
Sessão
Vá pacote padrão atualmente não fornece qualquer apoio para a sessão, a necessidade de conseguir por conta própria. Aplicação ver: https://astaxie.gitbooks.io/build-web-application-with-golang/content/zh/06.2.html
Você também pode usar beego quadro foi alcançado:
go get github.com/astaxie/beego/session
Veja: https://beego.me/docs/module/session.md
data
-
https://github.com/jinzhu/now
Agora é um momento para ir conjunto de ferramentas de linguagem. -
https://github.com/uniplaces/carbon
simples extensões de tempo, existem muitas formas úteis, é a interface de biblioteca PHP carbono.
O email
-
https://github.com/go-gomail/gomail
GoMail é uma biblioteca muito simples e poderoso para o envio de e-mail. -
https://github.com/jordan-wright/email
uma biblioteca de e-mail robusta e flexível. -
https://github.com/matcornic/hermes
para gerar um modelo limpo, HTML responsivo e-mail.
exemplo:
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
}
cronômetro
https://github.com/robfig/cron
referência
1, construir aplicações web com golang
https://astaxie.gitbooks.io/build-web-application-with-golang/zh/
2, avelino / incrível-go: uma lista de quadros Go impressionante, bibliotecas e software curadoria
https: //github.com/avelino/awesome-go
3, jobbole / incrível-go-cn: Go大全中文版资源
https://github.com/jobbole/awesome-go-cn
4, hackstoic / golang-open-source -Projetos:为互联网TI人打造的中文版incrível-go
https://github.com/hackstoic/golang-open-source-projects
5, Busca · incrível-go
https://github.com/search?q= impressionante-go