summaryrefslogtreecommitdiff
path: root/service/http/config.go
blob: 19a2e71deb5807cd2573116662c7d3e0d7925b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package http

import (
	"errors"
	"github.com/spiral/roadrunner"
	"strings"
)

// Config configures RoadRunner HTTP server.
type Config struct {
	// Enable enables http svc.
	Enable bool

	// Address and port to handle as http server.
	Address string

	// MaxRequest specified max size for payload body in megabytes, set 0 to unlimited.
	MaxRequest int64

	// Uploads configures uploads configuration.
	Uploads *UploadsConfig

	// Workers configures roadrunner server and worker pool.
	Workers *roadrunner.ServerConfig
}

// Valid validates the configuration.
func (cfg *Config) Valid() error {
	if cfg.Uploads == nil {
		return errors.New("mailformed uploads config")
	}

	if cfg.Workers == nil {
		return errors.New("mailformed workers config")
	}

	if cfg.Workers.Pool == nil {
		return errors.New("mailformed workers config (pool config is missing)")
	}

	if err := cfg.Workers.Pool.Valid(); err != nil {
		return err
	}

	if !strings.Contains(cfg.Address, ":") {
		return errors.New("mailformed server address")
	}

	return nil
}