github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/docs/config_zh.md (about) 1 # 配置 2 3 --- 4 5 ## Core 6 ```yaml 7 name: "foo" # 项目名称 8 runtime: # 服务运行时 9 maxWorkers: 0 # 最大 goroutines, 默认为 256 * 1024 10 workerMaxIdleSeconds: 10 # 最大协程空闲秒数, 默认为 10 11 handleTimeoutSeconds: 10 # 函数处理超时秒数, 默认为 10 12 ``` 13 ## Logger 14 ```yaml 15 log: 16 level: info # 等级: debug, info, warn, error 17 formatter: console # 输出格式: console, json 18 color: true # 是否开启色彩 19 ``` 20 ## Http 21 ```yaml 22 server: 23 port: 80 # 端口 24 cors: # cors, 默认是全部允许 25 allowedOrigins: 26 - "*" 27 allowedHeaders: 28 - "X-Foo" 29 exposedHeaders: 30 - "X-Foo" 31 allowCredentials: false 32 maxAge: 10 33 tls: # https, 默认为空 34 kind: "" # tls 类型: DEFAULT, SSC, ACME 35 options: {} # 类型配置 36 websocket: 37 readBufferSize: "4k" 38 writeBufferSize: "4k" 39 enableCompression: false 40 maxConns: 0 41 options: {} # 服务其它配置 42 interceptors: {} # 拦截器配置 43 ``` 44 ### TLS 45 `DEFAULT` 类型配置: 46 ```yaml 47 options: 48 cert: "证书路径" 49 key: "密钥路径" 50 ``` 51 `SSC` 类型配置: 52 ```yaml 53 options: 54 ca: "CA路径" 55 caKey: "CA密钥路径" 56 ``` 57 `ACME` 类型配置没有预设, 不过可以阅读 [ACMES](https://github.com/aacfactory/acmes) 来获取更多信息。 58 ```shell 59 go get github.com/aacfactory/acmes/client 60 ``` 61 创建ACME配置 62 ```go 63 type AcmeConfig struct { 64 CA string 65 Key string 66 Endpoint string 67 Domain string 68 } 69 ``` 70 注册ACME加载器 71 ```go 72 ssl.RegisterLoader("ACME", func(options configuares.Config) (serverTLS *tls.Config, clientTLS *tls.Config, err error) { 73 config := AcmeConfig{} 74 configErr := options.As(&config) 75 // handle configErr 76 ca, _ := ioutil.ReadFile(config.CA) 77 key, _ := ioutil.ReadFile(config.Key) 78 acme, connErr := client.New(ca, key, config.Endpoint) 79 // handle connErr 80 serverTLS, _, err = acme.Obtain(context.TODO(), config.Domain) 81 // handle err 82 }) 83 ``` 84 设置配置 85 ```yaml 86 options: 87 ca: "CA路径" 88 caKey: "CA密钥路径" 89 endpoint: "acme的服务端点" 90 domain: "待申请域名" 91 ``` 92 ### 服务配置 93 `Fasthttp` 配置: 94 ```yaml 95 options: 96 readTimeoutSeconds: 2 97 maxWorkerIdleSeconds: 10 98 maxRequestBody: "4MB" 99 reduceMemoryUsage: true 100 ``` 101 ### 拦截器配置 102 `pprof` 103 ```yaml 104 interceptors: 105 pprof: 106 password: "bcrypt password" 107 ``` 108 ## OpenAPI 109 ```yaml 110 oas: 111 title: "Project title" 112 description: | 113 Project description 114 terms: "https://terms.fns" 115 contact: 116 name: "hello" 117 url: "https://hello.fns" 118 email: "hello@fns" 119 license: 120 name: "license" 121 url: "https://license.fns" 122 servers: 123 - url: "https://test.hello.fns" 124 description: "test" 125 - url: "https://hello.fns" 126 description: "prod" 127 ``` 128 ## 集群配置 129 阅读 [doc](https://github.com/aacfactory/fns/blob/main/docs/cluster_zh.md) 获取更多信息。 130 ```yaml 131 cluster: 132 devMode: false # 开发模式,当开启后,本地开发的服务不会推送到集群中。 133 nodesProxyAddress: "ip:port" # 当开发模式开启后,如果需要访问集群但直接访问不行,则可以添加一个集群访问代理。 134 kind: "" # 集群类型: members, swarm, kubernetes. 135 client: 136 maxIdleConnSeconds: 0 137 maxConnsPerHost: 0 138 maxIdleConnsPerHost: 0 139 requestTimeoutSeconds: 0 140 options: {} # 集群类型的配置 141 ``` 142 ## 服务 143 根节点的名称为服务名,第二层节点一般是组件名(如果组件模式是被使用的). 144 举例: `jwt authorizations` 145 ```yaml 146 authorizations: 147 encoding: 148 method: "RS512" 149 publicKey: "path of public key" 150 privateKey: "path of private key" 151 issuer: "" 152 audience: 153 - "foo" 154 - "bar" 155 expirations: "720h0m0s" 156 store: {} 157 ```