初始化
This commit is contained in:
24
consul/consul.go
Normal file
24
consul/consul.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package consul
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||
"github.com/gogf/gf/contrib/registry/consul/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
_ "go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
consulCfg, err := g.Cfg().Get(context.Background(), "consul.address")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
consulAddr := consulCfg.String()
|
||||
registry, err := consul.New(consul.WithAddress(consulAddr))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gsvc.SetRegistry(registry)
|
||||
}
|
||||
Reference in New Issue
Block a user