Skip to content

caiyunapp/oap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decode Apollo config to strcut field

Install via:

go install github.com/caiyunapp/oap

Usage like:

import "github.com/caiyunapp/oap"

type DemoConfig struct {
	Int      int           `apollo:"int"`
	Int8     int8          `apollo:"int8"`
	Int16    int16         `apollo:"int16"`
	Int32    int32         `apollo:"int32"`
	Int64    int64         `apollo:"int64"`
	Uint     uint          `apollo:"uint"`
	Uint8    uint8         `apollo:"uint8"`
	Uint16   uint16        `apollo:"uint16"`
	Uint32   uint32        `apollo:"uint32"`
	Uint64   uint64        `apollo:"uint64"`
	Duration time.Duration `apollo:"duration"`
}

func main(){
	// init your apollo client here
	// ...

	conf := &DemoConfig{}
	if err := oap.Decode(conf, client, make(map[string][]agollo.OpOption)); err != nil {
		panic(err)
	}
}

Support types:

  • String
  • Int
  • Bool
  • Float32
  • Float64
  • Struct from JSON or YAML