johncming / go-spec

my wiki
Apache License 2.0
0 stars 0 forks source link

Controller实现 #116

Open johncming opened 5 years ago

johncming commented 5 years ago

Instance

控制器里面包含了实例 实例相当于server

Context

type httpContext struct {
    instance *caddy.Instance

    // keysToSiteConfigs maps an address at the top of a
    // server block (a "key") to its SiteConfig. Not all
    // SiteConfigs will be represented here, only ones
    // that appeared in the Caddyfile.
    keysToSiteConfigs map[string]*SiteConfig

    // siteConfigs is the master list of all site configs.
    siteConfigs []*SiteConfig
}

上下文实例有关系 实例站点配置有关系 服务类型是逻辑,控制器等相关是逻辑运行所需要的配置 控制器解析配置文件

johncming commented 5 years ago

注册serverTypes

httpserver plugin中默认注册一个http的服务类型

http服务类型

    caddy.RegisterServerType(serverType, caddy.ServerType{
        Directives: func() []string { return directives },
        DefaultInput: func() caddy.Input {
            if Port == DefaultPort && Host != "" {
                // by leaving the port blank in this case we give auto HTTPS
                // a chance to set the port to 443 for us
                return caddy.CaddyfileInput{
                    Contents:       []byte(fmt.Sprintf("%s\nroot %s", Host, Root)),
                    ServerTypeName: serverType,
                }
            }
            return caddy.CaddyfileInput{
                Contents:       []byte(fmt.Sprintf("%s:%s\nroot %s", Host, Port, Root)),
                ServerTypeName: serverType,
            }
        },
        NewContext: newContext,
    })

指令集

var directives = []string{
    // primitive actions that set up the fundamental vitals of each config
    "root",
    "index",
    "bind",
    "limits",
    "timeouts",
    "tls",

    // services/utilities, or other directives that don't necessarily inject handlers
    "startup",  // TODO: Deprecate this directive
    "shutdown", // TODO: Deprecate this directive
    "on",
    "supervisor", // github.com/lucaslorentz/caddy-supervisor
    "request_id",
    "realip", // github.com/captncraig/caddy-realip
    "git",    // github.com/abiosoft/caddy-git

    // directives that add listener middleware to the stack
    "proxyprotocol", // github.com/mastercactapus/caddy-proxyprotocol

    // directives that add middleware to the stack
    "locale", // github.com/simia-tech/caddy-locale
    "log",
    "cache", // github.com/nicolasazrak/caddy-cache
    "rewrite",
    "ext",
    "minify", // github.com/hacdias/caddy-minify
    "gzip",
    "header",
    "geoip", // github.com/kodnaplakal/caddy-geoip
    "errors",
    "authz",        // github.com/casbin/caddy-authz
    "filter",       // github.com/echocat/caddy-filter
    "ipfilter",     // github.com/pyed/ipfilter
    "ratelimit",    // github.com/xuqingfeng/caddy-rate-limit
    "expires",      // github.com/epicagency/caddy-expires
    "forwardproxy", // github.com/caddyserver/forwardproxy
    "basicauth",
    "redir",
    "status",
    "cors",      // github.com/captncraig/cors/caddy
    "s3browser", // github.com/techknowlogick/caddy-s3browser
    "nobots",    // github.com/Xumeiquer/nobots
    "mime",
    "login",     // github.com/tarent/loginsrv/caddy
    "reauth",    // github.com/freman/caddy-reauth
    "extauth",   // github.com/BTBurke/caddy-extauth
    "jwt",       // github.com/BTBurke/caddy-jwt
    "jsonp",     // github.com/pschlump/caddy-jsonp
    "upload",    // blitznote.com/src/caddy.upload
    "multipass", // github.com/namsral/multipass/caddy
    "internal",
    "pprof",
    "expvar",
    "push",
    "datadog",    // github.com/payintech/caddy-datadog
    "prometheus", // github.com/miekg/caddy-prometheus
    "templates",
    "proxy",
    "fastcgi",
    "cgi", // github.com/jung-kurt/caddy-cgi
    "websocket",
    "filebrowser", // github.com/filebrowser/caddy
    "webdav",      // github.com/hacdias/caddy-webdav
    "markdown",
    "browse",
    "mailout",   // github.com/SchumacherFM/mailout
    "awses",     // github.com/miquella/caddy-awses
    "awslambda", // github.com/coopernurse/caddy-awslambda
    "grpc",      // github.com/pieterlouw/caddy-grpc
    "gopkg",     // github.com/zikes/gopkg
    "restic",    // github.com/restic/caddy
    "wkd",       // github.com/emersion/caddy-wkd
    "dyndns",    // github.com/linkonoid/caddy-dyndns
}

输入

1.1.1.1:9090
root .

上下文

func newContext(inst *caddy.Instance) caddy.Context {
    return &httpContext{instance: inst, keysToSiteConfigs: make(map[string]*SiteConfig)}
}