common-go

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2021 License: MIT

README

common-go

made-with-Go Tag Test

Common code in Golang HTTP Server

Properties loader

Set struct value from environment

Usage

example:

export APP_NAME='Apple'
export APP_NUMBER=1
export APP_DIGIT=0.99
export APP_SOME_WORD='Yes, it is from environment'

main.go:

package main

import (
	"fmt"

	"github.com/tongium/common-go/pkg/properties"
)

type Configuration struct {
	Name     string  ``
	Number   int     `required:"true"`
	Digit    float64 ``
	SomeWord string  ``
}

func main() {
	cfg := Configuration{}
	err := properties.Load(&cfg)
	if err != nil {
		panic(err)
	}

	fmt.Println(cfg)
}

result:

{Apple 1 0.99 Yes, it is from environment}

Add required:"true" to return error if ENV not found

see more: example

Opentracing middleware

Set tags http.status_code, http.request_id and http.user_id

see more: example

with Echo

e := echo.New()
e.Use(middleware.RequestID(), echo.WrapMiddleware(tracing.OpentracingMiddleware()))

run Jeager all in one

docker run -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:latest

then make a request

curl --location --request GET 'http://localhost:8080/' \
	--header 'X-User-ID: 1'

then visit http://localhost:16686

Directories

Path Synopsis
example
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL