正常编译
GOOS=linux GOARCH=amd64 go build
小于 1 分钟
jzero >= v0.30.0+ 默认模板均支持动态配置特性
package dynamic_conf
import (
"os"
"path/filepath"
"github.com/a8m/envsubst"
"github.com/eddieowens/opts"
"github.com/fsnotify/fsnotify"
"github.com/zeromicro/go-zero/core/configcenter/subscriber"
"github.com/zeromicro/go-zero/core/logx"
)
var _ subscriber.Subscriber = (*FsNotify)(nil)
type FsNotify struct {
path string
// options
options FsNotifyOpts
*fsnotify.Watcher
}
type FsNotifyOpts struct {
UseEnv bool
}
func (opts FsNotifyOpts) DefaultOptions() FsNotifyOpts {
return FsNotifyOpts{}
}
func WithUseEnv(useEnv bool) opts.Opt[FsNotifyOpts] {
return func(o *FsNotifyOpts) {
o.UseEnv = useEnv
}
}
func NewFsNotify(path string, op ...opts.Opt[FsNotifyOpts]) (*FsNotify, error) {
o := opts.DefaultApply(op...)
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &FsNotify{
path: path,
Watcher: watcher,
options: o,
}, nil
}
func (f *FsNotify) AddListener(listener func()) error {
go func() {
for {
select {
case event, ok := <-f.Watcher.Events:
if !ok {
return
}
if (event.Has(fsnotify.Write) || event.Has(fsnotify.Rename)) &&
filepath.ToSlash(filepath.Clean(event.Name)) == filepath.Clean(filepath.ToSlash(f.path)) {
logx.Infof("listen %s %s event", event.Name, event.Op)
listener()
}
case err, ok := <-f.Watcher.Errors:
if !ok {
return
}
logx.Errorf("error: %v", err)
}
}
}()
// see: https://github.com/fsnotify/fsnotify/issues/363
if err := f.Watcher.Add(filepath.Dir(f.path)); err != nil {
return err
}
return nil
}
func (f *FsNotify) Value() (string, error) {
file, err := os.ReadFile(f.path)
if err != nil {
return "", err
}
if f.options.UseEnv {
file, err = envsubst.Bytes(file)
if err != nil {
return "", err
}
}
return string(file), nil
}
add MustGetConfig
method for ServiceContext
return config.Config
func (sc *ServiceContext) MustGetConfig() config.Config {
return sc.Config
}
jzero new core --feature serverless_core
cd core
jzero gen
go mod tidy
api 项目包含以下技术栈:
jzero new simpleapi --frame api
cd simpleapi
jzero gen
go mod tidy
欢迎参与 jzero 的开发以及维护, 这是一件非常有意义的事情, 让我们一起让 jzero 变得更好.
git clone https://github.com/your_username/jzero
目前仅支持 proto 可描述文件
jzero gen doc
syntax = "proto3";
message GetOrderRequest {
int32 order_id = 2;
}