summaryrefslogtreecommitdiff
path: root/types.go
blob: af7f30f6aef29fdff7c8a69d9e6fc55e2e054239 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main

import (
	"context"
	"crypto/tls"
	"net"
	"os/user"
	"text/template"

	"github.com/go-kit/log/level"
	"tildegit.org/tjp/sliderule"
)

type Modifiers struct {
	DirDefault        string
	DirList           bool
	Exec              bool
	ExecCmd           string
	ExtendedGophermap bool
	AutoAtom          bool
	Titan             *Auth
	Templates         *template.Template

	titanName string
}

func (m Modifiers) Empty() bool {
	return (m.DirDefault == "" &&
		!m.DirList &&
		!m.Exec &&
		!m.ExtendedGophermap &&
		m.ExecCmd == "" &&
		!m.AutoAtom &&
		m.Titan == nil &&
		m.titanName == "" &&
		m.Templates == nil)
}

type RouteDirective struct {
	// Allowed: "static", "cgi", "git", "titan"
	Type string

	// "<FsPath> at <URLPath>"
	FsPath  string
	URLPath string

	// "with ..."
	Modifiers Modifiers

	Auth     *Auth
	authName string
}

type Server struct {
	Type      string
	IP        net.IP
	Port      uint16
	TLS       *tls.Config
	Hostnames []string
	Routes    []RouteDirective

	tlsKeyFile  string
	tlsCertFile string
}

type Auth struct {
	Name     string
	Strategy AuthStrategy
}

type AuthStrategy interface {
	Approve(context.Context, *sliderule.Request) bool
}

type Configuration struct {
	SystemUser *user.User
	LogLevel   level.Value

	Servers []Server
}