The goal of this project is to make the easiest way of using Ctrip apollo for golang applications. This project has been forked from philchia/agollo since 2018.8 but change a lot.
Fork -> Patch -> Push -> Pull Request
- ✅ Multiple namespace support
- ✅ Fail tolerant
- ✅ Custom logger
- ❎ YML to struct
go 1.10 or later
If you want build this project,should use go 1.11+
GO111MODULE=on; go mod download
# go mod (only go 1.11+) or project in gopath(go 1.10 +)
go get -u gopkg.in/apollo.v0
# if you use dep as your golang dep tool (go 1.10)
dep ensure -add gopkg.in/apollo.v0
go-apoll use gopkg.in/logger.v1 as default logger provider. Any logger implemented apollo.Logger interface can be use as apollo logger provider(such as logrus).
//Logger interface
type Logger interface {
Warnf(format string, v ...interface{})
Warn(v ...interface{})
Errorf(format string, v ...interface{})
Error(v ...interface{})
Infof(format string, v ...interface{})
Info(v ...interface{})
Debugf(format string, v ...interface{})
Debug(v ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
}
set logrus as log provider
var log = logrus.New()
log.Formatter = new(logrus.JSONFormatter)
log.Formatter = new(logrus.TextFormatter) //default
log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors
log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
log.Level = logrus.TraceLevel
log.Out = os.Stdout
apollo.SetLogger(log)
apollo.Start()
apollo.StartWithConfFile(name)
events := apollo.WatchUpdate()
changeEvent := <-events
bytes, _ := json.Marshal(changeEvent)
fmt.Println("event:", string(bytes))
apollo.GetStringValue(Key, defaultValue)
apollo.GetStringValueWithNameSapce(namespace, key, defaultValue)
apollo.GetIntValue(Key, defaultValue)
apollo.GetIntValueWithNameSapce(namespace, key, defaultValue)
apollo.GetNameSpaceContent(namespace, defaultValue)
apollo is released under MIT lecense