Giter Site home page Giter Site logo

common-go's Introduction

common-go

Wrapper for common go library. Help you to reduce boilerplate code for initialization. Init once and use it everytime in your code.

Included library:

  1. Monitoring (Datadog)
  2. Tracker (Jaeger + Open Tracing)
  3. Logging (Logrus)
  4. Config Reader (Viper)

How to use

  1. 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"
)
  1. 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>",
    })
}
  1. 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")
}

License

MIT License

common-go's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.