Wrapper for common go library. Help you to reduce boilerplate code for initialization. Init once and use it everytime in your code.
Included library:
- Monitoring (Datadog)
- Tracker (Jaeger + Open Tracing)
- Logging (Logrus)
- Config Reader (Viper)
- Import your need to your Golang code
package main
import (
log "github.com/sleey/common-go/log"
datadog "github.com/sleey/common-go/datadog"
config "github.com/sleey/common-go/config"
tracer "github.com/sleey/common-go/tracer"
)
- Init the library
package main
import (
config "github.com/sleey/common-go/config"
log "github.com/sleey/common-go/log"
datadog "github.com/sleey/common-go/datadog"
tracer "github.com/sleey/common-go/tracer"
)
func init() {
// init config example
err := config.NewConfigFromFile("<config_name>", "<config_extension>", "<file_path>", config.NewConfigOptions{
DefaultName: "<config_default_name>",
})
// init log example
log.SetLogConfig(log.Config{
LogLevel: "debug",
ShortPath: false,
})
// init datadog example
datadog.InitDatadog(datadog.Config{
Endpoint: "<datadog_host>",
ServiceName: "<service_name>",
DefaultTags: []string{"env:production"},
})
tracer.Initialize(tracer.Config{
ServiceName: "<service_name>",
})
}
- Use the library
func main() {
log.Info("====== COMMON-GO =======")
test := config.GetString("test.config")
datadog.Histogram(test, time.Since(now).Seconds(), []string{"test"}, 1)
tracer.StartSpanFromContext(context.Background())
log.Info("END")
}
MIT License