Skip to content

Commit

Permalink
Merge pull request #25 from origadmin/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
godcong authored Nov 15, 2024
2 parents 538ce4e + e8c9de0 commit b32d1ee
Show file tree
Hide file tree
Showing 94 changed files with 8,445 additions and 6,748 deletions.
9 changes: 4 additions & 5 deletions codec/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
package codec

import (
"errors"
"io"
"os"
"path/filepath"

"github.com/origadmin/toolkits/codec/ini"
"github.com/origadmin/toolkits/codec/xml"
"github.com/origadmin/toolkits/errors"

"github.com/origadmin/toolkits/codec/json"
"github.com/origadmin/toolkits/codec/toml"
"github.com/origadmin/toolkits/codec/xml"
"github.com/origadmin/toolkits/codec/yaml"
)

const (
ErrUnsupportedDecodeType = errors.String("codec: unsupported decode type")
var (
ErrUnsupportedDecodeType = errors.New("codec: unsupported decode type")
)

// Decoder interface
Expand Down
7 changes: 3 additions & 4 deletions codec/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ package codec

import (
"encoding/xml"
"errors"
"io"
"os"
"path/filepath"

"github.com/origadmin/toolkits/codec/ini"
"github.com/origadmin/toolkits/errors"

"github.com/origadmin/toolkits/codec/json"
"github.com/origadmin/toolkits/codec/toml"
"github.com/origadmin/toolkits/codec/yaml"
)

const (
ErrUnsupportedEncodeType = errors.String("codec: unsupported encode type")
var (
ErrUnsupportedEncodeType = errors.New("codec: unsupported encode type")
)

// Encoder interface
Expand Down
7 changes: 0 additions & 7 deletions codec/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ go 1.23.1

toolchain go1.23.2

replace github.com/origadmin/toolkits => ../

require (
github.com/BurntSushi/toml v1.4.0
github.com/bytedance/sonic v1.12.4
github.com/goexts/generic v0.1.0
github.com/json-iterator/go v1.1.12
github.com/origadmin/toolkits v0.0.0-00010101000000-000000000000
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -20,13 +17,9 @@ require (
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/sys v0.27.0 // indirect
Expand Down
23 changes: 3 additions & 20 deletions codec/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,25 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goexts/generic v0.1.0 h1:C6xn8/Xu4KBGSFvMP0CMAhle5HDqqX3iShE3EKV3WYI=
github.com/goexts/generic v0.1.0/go.mod h1:j/ZjWHYt+If6VjeHWvDhYKdoP+gAiAKpm0cu3yvKmfo=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand All @@ -60,9 +44,8 @@ golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg=
golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
1 change: 0 additions & 1 deletion codec/json/std.go

This file was deleted.

77 changes: 27 additions & 50 deletions contrib/consul/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,67 @@ func init() {
runtime.RegisterRegistry("consul", &consulBuilder{})
}

func optsFromConfig(ccfg *config.Registry_Consul) []Option {
func optsFromConfig(registry *config.Registry) []Option {
var opts []Option

if ccfg.HealthCheck {
opts = append(opts, WithHealthCheck(ccfg.HealthCheck))
cfg := registry.GetConsul()
if cfg == nil {
return opts
}
if ccfg.HeartBeat {
opts = append(opts, WithHeartbeat(ccfg.HeartBeat))

if cfg.HealthCheck {
opts = append(opts, WithHealthCheck(cfg.HealthCheck))
}
if cfg.HeartBeat {
opts = append(opts, WithHeartbeat(cfg.HeartBeat))
}
if ccfg.Timeout != nil {
opts = append(opts, WithTimeout(ccfg.Timeout.AsDuration()))
if cfg.Timeout != nil {
opts = append(opts, WithTimeout(cfg.Timeout.AsDuration()))
}
if ccfg.Datacenter != "" {
opts = append(opts, WithDatacenter(Datacenter(ccfg.Datacenter)))
if cfg.Datacenter != "" {
opts = append(opts, WithDatacenter(Datacenter(cfg.Datacenter)))
}
if ccfg.HealthCheckInterval > 0 {
opts = append(opts, WithHealthCheckInterval(int(ccfg.HealthCheckInterval)))
if cfg.HealthCheckInterval > 0 {
opts = append(opts, WithHealthCheckInterval(int(cfg.HealthCheckInterval)))
}
if ccfg.DeregisterCriticalServiceAfter > 0 {
opts = append(opts, WithDeregisterCriticalServiceAfter(int(ccfg.DeregisterCriticalServiceAfter)))
if cfg.DeregisterCriticalServiceAfter > 0 {
opts = append(opts, WithDeregisterCriticalServiceAfter(int(cfg.DeregisterCriticalServiceAfter)))
}
//if true {
// consul.WithServiceResolver(func(ctx context.Context, entries []*api.ServiceEntry) []*registry.ServiceInstance {
// return []*registry.ServiceInstance{}
// })
// consul.WithServiceCheck()
//}
return opts
}

func (c *consulBuilder) NewDiscovery(cfg *config.Registry) (registry.Discovery, error) {
if cfg == nil || cfg.Consul == nil {
return nil, errors.New("configuration: consul config is required")
}
config := FromConfig(cfg.Consul)
config := fromConfig(cfg)
apiClient, err := api.NewClient(config)
if err != nil {
return nil, errors.Wrap(err, "failed to create consul client")
}
r := New(apiClient, optsFromConfig(cfg.Consul)...)
r := New(apiClient, optsFromConfig(cfg)...)
return r, nil
}

func (c *consulBuilder) NewRegistrar(cfg *config.Registry) (registry.Registrar, error) {
if cfg == nil || cfg.Consul == nil {
return nil, errors.New("configuration: consul config is required")
}
config := FromConfig(cfg.Consul)
config := fromConfig(cfg)
apiClient, err := api.NewClient(config)
if err != nil {
return nil, errors.Wrap(err, "failed to create consul client")
}
r := New(apiClient, optsFromConfig(cfg.Consul)...)
r := New(apiClient, optsFromConfig(cfg)...)
return r, nil
}

func FromConfig(cfg *config.Registry_Consul) *api.Config {
func fromConfig(registry *config.Registry) *api.Config {
apiconfig := api.DefaultConfig()
cfg := registry.GetConsul()
if cfg == nil {
return apiconfig
}
if cfg.Address != "" {
apiconfig.Address = cfg.Address
}
Expand All @@ -83,34 +86,8 @@ func FromConfig(cfg *config.Registry_Consul) *api.Config {
if cfg.Datacenter != "" {
apiconfig.Datacenter = cfg.Datacenter
}
//if cfg.PathPrefix != "" {
// apiconfig.PathPrefix = cfg.PathPrefix
//}
//if cfg.WaitTime != 0 {
// apiconfig.WaitTime = cfg.WaitTime
//}
if cfg.Token != "" {
apiconfig.Token = cfg.Token
}
//if cfg.TokenFile != "" {
// apiconfig.Token = cfg.TokenFile
//}
//if cfg.Namespace != "" {
// apiconfig.Namespace = cfg.Namespace
//}
//if cfg.Partition != "" {
// apiconfig.Partition = cfg.Partition
//}
//apiconfig.TLSConfig = api.TLSConfig{
// Address: cfg.TLSConfig.Address,
// CAFile: cfg.TLSConfig.CAFile,
// CAPath: cfg.TLSConfig.CAPath,
// CAPem: cfg.TLSConfig.CAPem,
// CertFile: cfg.TLSConfig.CertFile,
// CertPEM: cfg.TLSConfig.CertPEM,
// KeyFile: cfg.TLSConfig.KeyFile,
// KeyPEM: cfg.TLSConfig.KeyPEM,
// InsecureSkipVerify: cfg.TLSConfig.InsecureSkipVerify,
//}
return apiconfig
}
38 changes: 38 additions & 0 deletions examples/helloword/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: v2

managed:
enabled: true
# override:
# - file_option: go_package_prefix
# value: github.com/origadmin/toolkits/runtime
plugins:
- local: protoc-gen-go
out: services
opt: paths=source_relative
- local: protoc-gen-openapi
out: services
opt:
- naming=proto
- fq_schema_naming=true
- default_response=false
strategy: all # This tag will generate all files without split files in different directories.
- local: protoc-gen-validate
out: services
opt:
- paths=source_relative
- lang=go
- local: protoc-gen-go-http
out: services
opt: paths=source_relative
- local: protoc-gen-go-errors
out: services
opt: paths=source_relative
- local: protoc-gen-go-grpc
out: services
opt: paths=source_relative
- local: protoc-gen-go-gins
out: services
opt: paths=source_relative
# - remote: buf.build/community/google-gnostic-openapi:v0.7.0
# out: services
clean: true
12 changes: 12 additions & 0 deletions examples/helloword/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/bufbuild/protovalidate
commit: 5a7b106cbb87462d9a8c9ffecdbd2e38
digest: b5:0f2dc6c9453e9cc9e9f36807aaa5f94022e837d91fef4dcaeed79a35c0843cc64eba28ff077aab24da3b2cb12639ad256246f9f9a36c033b99d5754b19996b7e
- name: buf.build/googleapis/googleapis
commit: 553fd4b4b3a640be9b69a3fa0c17b383
digest: b5:9e7cb39758f3487f0751765227dc0b9f0ef7a401ab37fa2e97c363446810f4bd0dca1f46dbb793a12d98c019f4028e48d0831b5cb3f09190f068ec1866c69c1d
- name: buf.build/origadmin/runtime
commit: 886d2081631241cd84556d83c9425912
digest: b5:78562c87a34f0e109d6f474c522586a9225595c2d166b36ed748fb3c7790763b27ff9f004cd5c4f710065ea5da7295b35fe5a0644fbaecfe1407196907ffb406
17 changes: 17 additions & 0 deletions examples/helloword/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2

modules:
- path: proto

lint:
use:
- STANDARD

breaking:
use:
- FILE
deps:
- buf.build/googleapis/googleapis
- buf.build/origadmin/runtime
# - buf.build/envoyproxy/protoc-gen-validate
8 changes: 4 additions & 4 deletions examples/helloword/services/helloworld/v1/helloworld.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b32d1ee

Please sign in to comment.