Skip to content

imloama/gf-nacos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1eccf78 · Mar 10, 2021

History

15 Commits
Mar 9, 2021
Feb 26, 2021
Mar 10, 2021
Mar 10, 2021
Feb 26, 2021
Feb 26, 2021
Feb 26, 2021
Mar 9, 2021
Feb 26, 2021
Mar 10, 2021
Mar 9, 2021

Repository files navigation

goframe nacos plugin

使用nacos作为配置中心和服务注册管理,开发过程中,可能变动较大

version:0.0.8

默认使用toml配置文件

假设config.toml配置

[nacos]
    AppName = "example"
    Mode= "dev"
    FileExtension="toml"

那么会去nacos中查询${AppName}-${Mode}.${FileExtension}example-dev.toml的配置文件, 读取到配置内容后会覆盖g.Cfg中的内容,调用方法:gcfg.SetContent(content)

注意:

更新前会调用clear(),清理掉内存中之前读取的配置文件

示例

config.toml

main.go

[nacos]
    AppName = "example"
    Mode    = "dev"
    FileExtension = "toml"
    EnableConfig = true
    EnableDiscovery = true
    AppPort = 9000

[nacos.config]
    TimeoutMs = 5000
    NotLoadCacheAtStart = true
    RotateTime = "1h"
    MaxAge = 3
    LogLevel = "debug"

[nacos.discovery]
    Scheme = "http"
    ContextPath = "/nacos"
    IpAddr = "127.0.0.1"
    Port  = 8848

引用示例

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/imloama/gf-nacos"
)

func main(){
	g.Cfg().SetPath("./")
    s := g.Server()
    s.BindHandler("/", func(r *ghttp.Request) {
        r.Response.Write("hello, nacos!")
    })
    s.Plugin(&gfnacos.GfNacosPlugin{
        Listener: func(config string) {
            g.Log().Println("配置文件发生了更新!")
        },
    })
    s.Run()
}

About

goframe nacos plugin

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages