Skip to content

Commit

Permalink
补充默认配置样例
Browse files Browse the repository at this point in the history
  • Loading branch information
yumaojun03 committed Dec 20, 2023
1 parent 88eaa61 commit 32f610d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 12 deletions.
58 changes: 49 additions & 9 deletions examples/etc/application.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
[app]
name = "exapmle"
key = "this is your app key"
name = "mcube_app"
description = ""
encrypt_key = "defualt app encrypt key"
cipher_prefix = "@ciphered@"

[app.http]
host = "127.0.0.1"
port = 8020
enable = false
host = "127.0.0.1"
port = 8010
path_prefix = "api"
web_framework = ""
read_header_timeout = 30
read_timeout = 60
write_timeout = 60
idle_timeout = 300
max_header_size = "16kb"
enable_ssl = false
cert_file = ""
key_file = ""
enable_trace = false

[log]
level = "debug"
[app.http.health_check]
enabled = true

[log.file]
enable = true
file_path = "logs/app.log"
[app.http.cors]
enabled = false
cors_allowed_headers = ["*"]
cors_allowed_domains = ["*"]
cors_allowed_methods = ["HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE"]

[app.http.api_doc]
enabled = true
doc_path = "/apidocs.json"

[app.grpc]
enable = false
host = "127.0.0.1"
port = 18010
enable_ssl = false
cert_file = ""
key_file = ""
enable_recovery = true
enable_trace = true

[app.trace]
enable = false
provider = "jaeger"
endpoint = "http://localhost:14268/api/traces"

[app.metric]
enable = false
provider = "prometheus"
endpoint = "/metrics"
2 changes: 2 additions & 0 deletions examples/rpc_grpc/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ func main() {
panic(err)
}
}


2 changes: 1 addition & 1 deletion ioc/config/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func init() {
ioc.Config().Registry(&Application{
AppName: "mcube_service",
AppName: "mcube_app",
EncryptKey: "defualt app encrypt key",
CipherPrefix: "@ciphered@",
Trace: NewDefaultTrace(),
Expand Down
11 changes: 11 additions & 0 deletions ioc/config/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ import (
"os"
"testing"

"github.com/BurntSushi/toml"
"github.com/infraboard/mcube/v2/ioc"
"github.com/infraboard/mcube/v2/ioc/config/application"
)

func TestGetClientGetter(t *testing.T) {
m := application.App()
t.Log(m.HTTP.EnableTrace)

}

func TestDefaultConfig(t *testing.T) {
f, err := os.OpenFile("test/default.toml", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
t.Fatal(err)
}
appConf := map[string]any{application.AppName: application.App()}
toml.NewEncoder(f).Encode(appConf)
}

func init() {
Expand Down
4 changes: 2 additions & 2 deletions ioc/config/application/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Http struct {
// 默认根据
Enable *bool `json:"enable" yaml:"enable" toml:"enable" env:"ENABLE"`
// HTTP服务Host
Host string `json:"size" yaml:"size" toml:"size" env:"HOST"`
Host string `json:"host" yaml:"host" toml:"host" env:"HOST"`
// HTTP服务端口
Port int `json:"port" yaml:"port" toml:"port" env:"PORT"`
// 接口前缀
Expand Down Expand Up @@ -93,7 +93,7 @@ type Http struct {
server *http.Server
routerBuilders map[WEB_FRAMEWORK]RouterBuilder `json:"-" yaml:"-" toml:"-" env:"-"`
handlerCount map[WEB_FRAMEWORK]int `json:"-" yaml:"-" toml:"-" env:"-"`
RouterBuildConfig *BuildConfig
RouterBuildConfig *BuildConfig `json:"-" yaml:"-" toml:"-" env:"-"`
}

type HealthCheck struct {
Expand Down
47 changes: 47 additions & 0 deletions ioc/config/application/test/default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[app]
name = "mcenter"
description = ""
encrypt_key = "defualt app encrypt key"
cipher_prefix = "@ciphered@"
[app.trace]
enable = false
provider = "jaeger"
endpoint = "http://localhost:14268/api/traces"
[app.metric]
enable = false
provider = "prometheus"
endpoint = "/metrics"
[app.http]
enable = false
size = "127.0.0.1"
port = 8010
path_prefix = "api"
web_framework = ""
read_header_timeout = 30
read_timeout = 60
write_timeout = 60
idle_timeout = 300
max_header_size = "16kb"
enable_ssl = false
cert_file = ""
key_file = ""
enable_trace = false
[app.http.health_check]
enabled = true
[app.http.cors]
enabled = false
cors_allowed_headers = ["*"]
cors_allowed_domains = ["*"]
cors_allowed_methods = ["HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE"]
[app.http.api_doc]
enabled = true
doc_path = "/apidocs.json"
[app.grpc]
enable = false
host = "127.0.0.1"
port = 18010
enable_ssl = false
cert_file = ""
key_file = ""
enable_recovery = true
enable_trace = true

0 comments on commit 32f610d

Please sign in to comment.