Categorygithub.com/tongium/common-go
module
0.2.0
Repository: https://github.com/tongium/common-go.git
Documentation: pkg.go.dev

# README

common-go

made-with-Go Go: Version Tag Test License: MIT

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

# Packages

No description provided by the author
No description provided by the author