Documentation
¶
Overview ¶
Package config provides configuration structures, validation, and defaulting for up.json config.
Index ¶
- Constants
- type Backoff
- type CORS
- type Config
- type DNS
- type Duration
- type Environment
- type ErrorPages
- type Hook
- type Hooks
- type IAMPolicyStatement
- type Lambda
- type Logs
- type Record
- type Relay
- type Runtime
- type Stage
- type StageOverrides
- type Stages
- func (s Stages) Default() error
- func (s Stages) Domains() (v []string)
- func (s Stages) GetByDomain(domain string) *Stage
- func (s Stages) GetByName(name string) *Stage
- func (s Stages) List() (v []*Stage)
- func (s Stages) Names() (v []string)
- func (s Stages) RemoteNames() (v []string)
- func (s Stages) Validate() error
- type Static
- type VPC
- type Zone
Examples ¶
Constants ¶
const ( RuntimeUnknown Runtime = "unknown" RuntimeGo = "go" RuntimeNode = "node" RuntimeClojure = "clojure" RuntimeCrystal = "crystal" RuntimePython = "python" RuntimeStatic = "static" RuntimeJavaMaven = "java maven" RuntimeJavaGradle = "java gradle" )
Runtimes available.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct {
// Min time in milliseconds.
Min int `json:"min"`
// Max time in milliseconds.
Max int `json:"max"`
// Factor applied for every attempt.
Factor float64 `json:"factor"`
// Attempts performed before failing.
Attempts int `json:"attempts"`
// Jitter is applied when true.
Jitter bool `json:"jitter"`
}
Backoff config.
type CORS ¶
type CORS struct {
// AllowedOrigins is a list of origins a cross-domain request can be executed from.
// If the special "*" value is present in the list, all origins will be allowed.
// An origin may contain a wildcard (*) to replace 0 or more characters
// (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penalty.
// Only one wildcard can be used per origin.
// Default value is ["*"]
AllowedOrigins []string `json:"allowed_origins"`
// AllowedMethods is a list of methods the client is allowed to use with
// cross-domain requests. Default value is simple methods (GET and POST)
AllowedMethods []string `json:"allowed_methods"`
// AllowedHeaders is list of non simple headers the client is allowed to use with
// cross-domain requests.
// If the special "*" value is present in the list, all headers will be allowed.
// Default value is [] but "Origin" is always appended to the list.
AllowedHeaders []string `json:"allowed_headers"`
// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
// API specification
ExposedHeaders []string `json:"exposed_headers"`
// AllowCredentials indicates whether the request can include user credentials like
// cookies, HTTP authentication or client side SSL certificates.
AllowCredentials bool `json:"allow_credentials"`
// MaxAge indicates how long (in seconds) the results of a preflight request
// can be cached.
MaxAge int `json:"max_age"`
// Debugging flag adds additional output to debug server side CORS issues
Debug bool `json:"debug"`
}
CORS configuration.
type Config ¶
type Config struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Headers header.Rules `json:"headers"`
Redirects redirect.Rules `json:"redirects"`
Hooks Hooks `json:"hooks"`
Environment Environment `json:"environment"`
Regions []string `json:"regions"`
Profile string `json:"profile"`
Inject inject.Rules `json:"inject"`
Lambda Lambda `json:"lambda"`
CORS *CORS `json:"cors"`
ErrorPages ErrorPages `json:"error_pages"`
Proxy Relay `json:"proxy"`
Static Static `json:"static"`
Logs Logs `json:"logs"`
Stages Stages `json:"stages"`
DNS DNS `json:"dns"`
}
Config for the project.
func MustParseConfigString ¶
MustParseConfigString returns config from JSON string.
func ParseConfig ¶
ParseConfig returns config from JSON bytes.
func ParseConfigString ¶
ParseConfigString returns config from JSON string.
func ReadConfig ¶
ReadConfig reads the configuration from `path`.
type DNS ¶
type DNS struct {
Zones []*Zone `json:"zones"`
}
DNS config.
Example ¶
s := `{
"something.sh": [
{
"name": "something.com",
"type": "A",
"ttl": 60,
"value": ["35.161.83.243"]
},
{
"name": "blog.something.com",
"type": "CNAME",
"ttl": 60,
"value": ["34.209.172.67"]
},
{
"name": "api.something.com",
"type": "A",
"value": ["54.187.185.18"]
}
]
}`
var c DNS
if err := json.Unmarshal([]byte(s), &c); err != nil {
log.Fatalf("error unmarshaling: %s", err)
}
sort.Slice(c.Zones[0].Records, func(i int, j int) bool {
a := c.Zones[0].Records[i]
b := c.Zones[0].Records[j]
return a.Name > b.Name
})
if err := c.Validate(); err != nil {
log.Fatalf("error validating: %s", err)
}
if err := c.Default(); err != nil {
log.Fatalf("error defaulting: %s", err)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(c)
Output: { "zones": [ { "name": "something.sh", "records": [ { "name": "something.com", "type": "A", "ttl": 60, "value": [ "35.161.83.243" ] }, { "name": "blog.something.com", "type": "CNAME", "ttl": 60, "value": [ "34.209.172.67" ] }, { "name": "api.something.com", "type": "A", "ttl": 300, "value": [ "54.187.185.18" ] } ] } ] }
func (*DNS) UnmarshalJSON ¶
UnmarshalJSON implementation.
type Duration ¶
Duration may be specified as numerical seconds or as a duration string such as "1.5m".
func (*Duration) MarshalJSON ¶
MarshalJSON implement.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implementation.
type ErrorPages ¶
type ErrorPages struct {
// Enable error pages.
Enable bool `json:"enable"`
// Dir containing error pages.
Dir string `json:"dir"`
// Variables are passed to the template for use.
Variables map[string]interface{} `json:"variables"`
}
ErrorPages configuration.
type Hook ¶
type Hook []string
Hook is one or more commands.
func (*Hook) UnmarshalJSON ¶
UnmarshalJSON implementation.
type Hooks ¶
type Hooks struct {
Build Hook `json:"build"`
Clean Hook `json:"clean"`
PreBuild Hook `json:"prebuild"`
PostBuild Hook `json:"postbuild"`
PreDeploy Hook `json:"predeploy"`
PostDeploy Hook `json:"postdeploy"`
}
Hooks for the project.
type IAMPolicyStatement ¶
type IAMPolicyStatement map[string]interface{}
IAMPolicyStatement configuration.
type Lambda ¶
type Lambda struct {
// Memory of the function.
Memory int `json:"memory"`
// Timeout of the function.
Timeout int `json:"timeout"`
// Role of the function.
Role string `json:"role"`
// Runtime of the function.
Runtime string `json:"runtime"`
// Policy of the function role.
Policy []IAMPolicyStatement `json:"policy"`
// VPC configuration.
VPC *VPC `json:"vpc"`
}
Lambda configuration.
type Logs ¶
type Logs struct {
// Disable json log output.
Disable bool `json:"disable"`
// Stdout default log level.
Stdout string `json:"stdout"`
// Stderr default log level.
Stderr string `json:"stderr"`
}
Logs configuration.
type Record ¶
type Record struct {
Name string `json:"name"`
Type string `json:"type"`
TTL int `json:"ttl"`
Value []string `json:"value"`
}
Record is a DNS record.
type Relay ¶
type Relay struct {
// Command run to start your server.
Command string `json:"command"`
// Timeout in seconds to wait for a response.
Timeout int `json:"timeout"`
// ListenTimeout in seconds when waiting for the app to bind to PORT.
ListenTimeout int `json:"listen_timeout"`
}
Relay config.
type Stage ¶
type Stage struct {
Domain string `json:"domain"`
Zone interface{} `json:"zone"`
Path string `json:"path"`
Cert string `json:"cert"`
Name string `json:"-"`
StageOverrides
}
Stage config.
type StageOverrides ¶
type StageOverrides struct {
Hooks Hooks `json:"hooks"`
Lambda Lambda `json:"lambda"`
Proxy Relay `json:"proxy"`
}
StageOverrides config.
type Stages ¶
Stages config.
func (Stages) GetByDomain ¶
GetByDomain returns the stage by domain or nil.
func (Stages) RemoteNames ¶
RemoteNames returns configured remote stage names.
type Static ¶
type Static struct {
// Dir containing static files.
Dir string `json:"dir"`
// Prefix is an optional URL prefix for serving static files.
Prefix string `json:"prefix"`
}
Static configuration.