github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/docs/config.md (about)

     1  # Configuration
     2  
     3  ---
     4  
     5  ## Core
     6  ```yaml
     7  name: "foo"                   # project name
     8  runtime:                      # service runtime
     9    maxWorkers: 0               # max goroutines, default is 256 * 1024
    10    workerMaxIdleSeconds: 10    # max idle goroutine second, default is 10
    11    handleTimeoutSeconds: 10    # fn request handle timeout, default is 10
    12  ```
    13  ## Logger
    14  ```yaml
    15  log:
    16    level: info                 # level: debug, info, warn, error
    17    formatter: console          # output formatter: console, json
    18    color: true                 # enable or disable colorful console output
    19  ```
    20  ## Http
    21  ```yaml
    22  server:
    23    port: 80                    # port
    24    cors:                       # cors, default is allow all
    25      allowedOrigins:
    26        - "*"
    27      allowedHeaders:
    28        - "X-Foo"
    29      exposedHeaders:
    30        - "X-Foo"
    31      allowCredentials: false
    32      maxAge: 10
    33    tls:                        # https, default is nil
    34      kind: ""                  # tls kind: DEFAULT, SSC, ACME 
    35      options: {}               # options of kind
    36    websocket:
    37      readBufferSize: "4k"
    38      writeBufferSize: "4k"
    39      enableCompression: false
    40      maxConns: 0
    41    options: {}                 # http server options
    42    interceptors: {}            # http interceptors config
    43  ```
    44  ### TLS
    45  `DEFAULT` kind options: 
    46  ```yaml
    47  options: 
    48    cert: "path of cert pem file"
    49    key: "path of private key pem file"
    50  ```
    51  `SSC` kind options:
    52  ```yaml
    53  options:
    54    ca: "path of ca pem file"
    55    caKey: "path of private key pem file"
    56  ```
    57  `ACME` kind options is not defined, but you can use [ACMES](https://github.com/aacfactory/acmes)
    58  ```shell
    59  go get github.com/aacfactory/acmes/client
    60  ```
    61  Make options type
    62  ```go
    63  type AcmeConfig struct {
    64  	CA string 
    65  	Key string
    66  	Endpoint string
    67  	Domain string
    68  }
    69  ```
    70  Register ACME Loader
    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  set options
    85  ```yaml
    86  options:
    87    ca: "path of ca pem file"
    88    caKey: "path of private key pem file"
    89    endpoint: "endpoint of acmes server"
    90    domain: "which domain to be obtained"
    91  ```
    92  ### Server Options
    93  `Fasthttp` options:
    94  ```yaml
    95  options:
    96    readTimeoutSeconds: 2
    97    maxWorkerIdleSeconds: 10
    98    maxRequestBody: "4MB"
    99    reduceMemoryUsage: true
   100  ```
   101  ### Interceptors
   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  ## Cluster
   129  cluster config, read [doc](https://github.com/aacfactory/fns/blob/main/docs/cluster.md) for more.
   130  ```yaml
   131  cluster:
   132    devMode: false                  # when dev mode is true, current node will not be pushed to other members
   133    nodesProxyAddress: "ip:port"    # when dev mode is true, and current node can not use member address to access them, then use a proxy to access members. 
   134    kind: ""                        # cluster kind: members, swarm, kubernetes.
   135    client:
   136      maxIdleConnSeconds: 0
   137      maxConnsPerHost: 0
   138      maxIdleConnsPerHost: 0
   139      requestTimeoutSeconds: 0
   140    options: {}                     # options of kind
   141  ```
   142  ## Service
   143  service config, name of root node is service name, second layer nodes are components (if components are used).   
   144  For example: `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  ```