vaya paquete común de terceros

configuración

van-este / estos

formato de archivo de configuración INI para la lectura.

Dirección: https://github.com/Go-ini/ini

TOMAL

Conf formato para leer el archivo de configuración.

Dirección: https://github.com/BurntSushi/toml

go-yaml / yaml

yaml formato para leer el archivo de configuración.

Dirección: https://github.com/go-yaml/yaml

wblog / system.go al maestro · 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 es un sistema de registro implementado con el lenguaje Go, es totalmente compatible con el registro de la biblioteca estándar y API central es muy estable, el idioma Go es actualmente la biblioteca más activo de registro.

  • https://github.com/uber-go/zap
    rápido, estructurado y jerárquico de soporte de base de datos de registro.

  • https://github.com/golang/glog
    clasificación de la biblioteca de registro.

  • https://github.com/cihub/seelog
    seelog Go es un sistema de registro de la lengua, que proporciona algunas funciones simples obtenidos a través de la distribución log complejo, el filtrado y de formato.

beego / logs

Documentación: https://beego.me/docs/module/logs.md

Ejemplo:

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...")

Perfiles?

Ver: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/12.1.html

Sesión

Ir paquete estándar actualmente no proporciona ningún apoyo para la sesión, la necesidad de lograr por sí solos. Véase la aplicación: https://astaxie.gitbooks.io/build-web-application-with-golang/content/zh/06.2.html

También puede utilizar se ha logrado beego marco:

go get github.com/astaxie/beego/session

Ver: https://beego.me/docs/module/session.md

fecha

Email

Ejemplo:

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

}

temporizador

https://github.com/robfig/cron

referencia

1, Construir aplicaciones web con Golang
https://astaxie.gitbooks.io/build-web-application-with-golang/zh/
2, Avelino / impresionante-Go: Una lista de los marcos impresionantes Go, bibliotecas y software curada
https: //github.com/avelino/awesome-go
3, jobbole / awesome-go-cn: Ir中文版大全资源
https://github.com/jobbole/awesome-go-cn
4, hackstoic / golang-abrir-fuente -Proyectos:为互联网TI人打造的中文版impresionante marcha
https://github.com/hackstoic/golang-open-source-projects
5, Buscar · impresionante marcha
https://github.com/search?q= impresionante-go

Supongo que te gusta

Origin www.cnblogs.com/52fhy/p/12584574.html
Recomendado
Clasificación