diff --git a/caddy/caddy.go b/caddy/caddy.go index 937e4b6b5..952480769 100644 --- a/caddy/caddy.go +++ b/caddy/caddy.go @@ -37,7 +37,8 @@ import ( // Configurable application parameters var ( // The name and version of the application. - AppName, AppVersion string + AppName string + AppVersion string // If true, initialization will not show any informative output. Quiet bool @@ -53,9 +54,9 @@ var ( // caddyfileMu protects caddyfile during changes caddyfileMu sync.Mutex - // incompleteRestartErr occurs if this process is a fork + // errIncompleteRestart occurs if this process is a fork // of the parent but no Caddyfile was piped in - incompleteRestartErr = errors.New("cannot finish restart successfully") + errIncompleteRestart = errors.New("cannot finish restart successfully") // servers is a list of all the currently-listening servers servers []*server.Server @@ -74,8 +75,11 @@ var ( ) const ( + // DefaultHost is the default host. DefaultHost = "0.0.0.0" + // DefaultPort is the default port. DefaultPort = "2015" + // DefaultRoot is the default root folder. DefaultRoot = "." ) diff --git a/caddy/caddyfile/json.go b/caddy/caddyfile/json.go index 42171e7a6..59cc8e0d7 100644 --- a/caddy/caddyfile/json.go +++ b/caddy/caddyfile/json.go @@ -155,8 +155,10 @@ func jsonToText(scope interface{}, depth int) string { return result } +// Caddyfile encapsulates a slice of ServerBlocks. type Caddyfile []ServerBlock +// ServerBlock represents a server block. type ServerBlock struct { Hosts []string `json:"hosts"` Body map[string]interface{} `json:"body"` diff --git a/caddy/config.go b/caddy/config.go index 3914290d0..6a311ee80 100644 --- a/caddy/config.go +++ b/caddy/config.go @@ -280,7 +280,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) { // change them to 80 or 443 respectively. If a hostname fails to // resolve, that host can still be served but will be listening on // the wildcard host instead. This function takes care of this for you. -func resolveAddr(conf server.Config) (resolvAddr *net.TCPAddr, warnErr error, fatalErr error) { +func resolveAddr(conf server.Config) (resolvAddr *net.TCPAddr, warnErr, fatalErr error) { bindHost := conf.BindHost // TODO: Do we even need the port? Maybe we just need to look up the host. diff --git a/caddy/helpers.go b/caddy/helpers.go index c7a467c66..c7cc479ce 100644 --- a/caddy/helpers.go +++ b/caddy/helpers.go @@ -67,5 +67,5 @@ func (c CaddyfileInput) Body() []byte { return c.Contents } // Path returns c.Filepath. func (c CaddyfileInput) Path() string { return c.Filepath } -// Path returns true if the original input was a real file on the file system. +// IsFile returns true if the original input was a real file on the file system. func (c CaddyfileInput) IsFile() bool { return c.RealFile } diff --git a/caddy/letsencrypt/letsencrypt.go b/caddy/letsencrypt/letsencrypt.go index 2ad1a126b..5a366c6b3 100644 --- a/caddy/letsencrypt/letsencrypt.go +++ b/caddy/letsencrypt/letsencrypt.go @@ -398,9 +398,9 @@ func otherHostHasScheme(allConfigs []server.Config, cfgIndex int, scheme string) // be the HTTPS configuration. The returned configuration is set // to listen on the "http" port (port 80). func redirPlaintextHost(cfg server.Config) server.Config { - toUrl := "https://" + cfg.Host + toURL := "https://" + cfg.Host if cfg.Port != "https" && cfg.Port != "http" { - toUrl += ":" + cfg.Port + toURL += ":" + cfg.Port } redirMidware := func(next middleware.Handler) middleware.Handler { @@ -408,7 +408,7 @@ func redirPlaintextHost(cfg server.Config) server.Config { { FromScheme: "http", FromPath: "/", - To: toUrl + "{uri}", + To: toURL + "{uri}", Code: http.StatusMovedPermanently, }, }} @@ -459,13 +459,13 @@ func Revoke(host string) error { } var ( - // Let's Encrypt account email to use if none provided + // DefaultEmail represents the Let's Encrypt account email to use if none provided DefaultEmail string - // Whether user has agreed to the Let's Encrypt SA + // Agreed indicates whether user has agreed to the Let's Encrypt SA Agreed bool - // The base URL to the CA's ACME endpoint + // CAUrl represents the base URL to the CA's ACME endpoint CAUrl string ) diff --git a/caddy/letsencrypt/storage.go b/caddy/letsencrypt/storage.go index 81c0aaea9..7a00aa18a 100644 --- a/caddy/letsencrypt/storage.go +++ b/caddy/letsencrypt/storage.go @@ -26,7 +26,7 @@ func (s Storage) Site(domain string) string { return filepath.Join(s.Sites(), domain) } -// CertFile returns the path to the certificate file for domain. +// SiteCertFile returns the path to the certificate file for domain. func (s Storage) SiteCertFile(domain string) string { return filepath.Join(s.Site(domain), domain+".crt") } diff --git a/caddy/parse/parse.go b/caddy/parse/parse.go index 84043e606..cb302d419 100644 --- a/caddy/parse/parse.go +++ b/caddy/parse/parse.go @@ -8,8 +8,8 @@ import "io" // If checkDirectives is true, only valid directives will be allowed // otherwise we consider it a parse error. Server blocks are returned // in the order in which they appear. -func ServerBlocks(filename string, input io.Reader, checkDirectives bool) ([]serverBlock, error) { - p := parser{Dispenser: NewDispenser(filename, input), checkDirectives: checkDirectives} +func ServerBlocks(filename string, input io.Reader) ([]serverBlock, error) { + p := parser{Dispenser: NewDispenser(filename, input)} blocks, err := p.parseAll() return blocks, err } @@ -26,6 +26,6 @@ func allTokens(input io.Reader) (tokens []token) { return } -// Set of directives that are valid (unordered). Populated +// ValidDirectives is a set of directives that are valid (unordered). Populated // by config package's init function. var ValidDirectives = make(map[string]struct{}) diff --git a/caddy/restart.go b/caddy/restart.go index eae8604ff..30f80ba6c 100644 --- a/caddy/restart.go +++ b/caddy/restart.go @@ -94,7 +94,7 @@ func Restart(newCaddyfile Input) error { answer, err := ioutil.ReadAll(sigrpipe) if err != nil || len(answer) == 0 { log.Println("restart: child failed to initialize; changes not applied") - return incompleteRestartErr + return errIncompleteRestart } // Child process is listening now; we can stop all our servers here. diff --git a/caddy/setup/bindhost.go b/caddy/setup/bindhost.go index 3e4bf89b3..363163dcb 100644 --- a/caddy/setup/bindhost.go +++ b/caddy/setup/bindhost.go @@ -2,6 +2,7 @@ package setup import "github.com/mholt/caddy/middleware" +// BindHost sets the host to bind the listener to. func BindHost(c *Controller) (middleware.Middleware, error) { for c.Next() { if !c.Args(&c.BindHost) { diff --git a/caddy/setup/root.go b/caddy/setup/root.go index 892578b7a..c24b39fb0 100644 --- a/caddy/setup/root.go +++ b/caddy/setup/root.go @@ -7,6 +7,7 @@ import ( "github.com/mholt/caddy/middleware" ) +// Root sets up the root file path of the server. func Root(c *Controller) (middleware.Middleware, error) { for c.Next() { if !c.NextArg() { diff --git a/caddy/setup/startupshutdown.go b/caddy/setup/startupshutdown.go index e4d873056..d09831cdf 100644 --- a/caddy/setup/startupshutdown.go +++ b/caddy/setup/startupshutdown.go @@ -8,10 +8,12 @@ import ( "github.com/mholt/caddy/middleware" ) +// Startup registers a startup callback to execute during server start. func Startup(c *Controller) (middleware.Middleware, error) { return nil, registerCallback(c, &c.Startup) } +// Shutdown registers a shutdown callback to execute during process exit. func Shutdown(c *Controller) (middleware.Middleware, error) { return nil, registerCallback(c, &c.Shutdown) } diff --git a/caddy/setup/tls.go b/caddy/setup/tls.go index bef6da9dd..649c2eccb 100644 --- a/caddy/setup/tls.go +++ b/caddy/setup/tls.go @@ -9,6 +9,7 @@ import ( "github.com/mholt/caddy/server" ) +// TLS sets up the TLS configuration (but does not activate Let's Encrypt; that is handled elsewhere). func TLS(c *Controller) (middleware.Middleware, error) { if c.Port == "http" { c.TLS.Enabled = false diff --git a/middleware/basicauth/basicauth.go b/middleware/basicauth/basicauth.go index 14e7d2105..ebfd0a8e6 100644 --- a/middleware/basicauth/basicauth.go +++ b/middleware/basicauth/basicauth.go @@ -78,7 +78,7 @@ type Rule struct { Resources []string } -// PasswordMatcher determines whether a password mathes a rule. +// PasswordMatcher determines whether a password matches a rule. type PasswordMatcher func(pw string) bool var ( @@ -86,6 +86,7 @@ var ( htpasswordsMu sync.Mutex ) +// GetHtpasswdMatcher matches password rules. func GetHtpasswdMatcher(filename, username, siteRoot string) (PasswordMatcher, error) { filename = filepath.Join(siteRoot, filename) htpasswordsMu.Lock() diff --git a/middleware/browse/browse_test.go b/middleware/browse/browse_test.go index 2d653c98e..a0c2cb244 100644 --- a/middleware/browse/browse_test.go +++ b/middleware/browse/browse_test.go @@ -223,7 +223,7 @@ func TestBrowseJson(t *testing.T) { listing := Listing{Items: fileinfos} // this listing will be used for validation inside the tests tests := []struct { - QueryUrl string + QueryURL string SortBy string OrderBy string Limit int @@ -263,7 +263,7 @@ func TestBrowseJson(t *testing.T) { for i, test := range tests { var marsh []byte - req, err := http.NewRequest("GET", "/photos"+test.QueryUrl, nil) + req, err := http.NewRequest("GET", "/photos"+test.QueryURL, nil) if err == nil && test.shouldErr { t.Errorf("Test %d didn't error, but it should have", i) diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 3104bc4cc..77fb668f1 100755 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -278,6 +278,6 @@ type Rule struct { var ( headerNameReplacer = strings.NewReplacer(" ", "_", "-", "_") - + // ErrIndexMissingSplit describes an index configuration error. ErrIndexMissingSplit = errors.New("configured index file(s) must include split value") ) diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index de46a4e8e..b8b03fe76 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -30,44 +30,75 @@ import ( "sync" ) +// FCGIListenSockFileno describes listen socket file number. const FCGIListenSockFileno uint8 = 0 + +// FCGIHeaderLen describes header length. const FCGIHeaderLen uint8 = 8 + +// Version1 describes the version. const Version1 uint8 = 1 + +// FCGINullRequestID describes the null request ID. const FCGINullRequestID uint8 = 0 + +// FCGIKeepConn describes keep connection mode. const FCGIKeepConn uint8 = 1 const doubleCRLF = "\r\n\r\n" const ( + // BeginRequest is the begin request flag. BeginRequest uint8 = iota + 1 + // AbortRequest is the abort request flag. AbortRequest + // EndRequest is the end request flag. EndRequest + // Params is the parameters flag. Params + // Stdin is the standard input flag. Stdin + // Stdout is the standard output flag. Stdout + // Stderr is the standard error flag. Stderr + // Data is the data flag. Data + // GetValues is the get values flag. GetValues + // GetValuesResult is the get values result flag. GetValuesResult + // UnknownType is the unknown type flag. UnknownType + // MaxType is the maximum type flag. MaxType = UnknownType ) const ( + // Responder is the responder flag. Responder uint8 = iota + 1 + // Authorizer is the authorizer flag. Authorizer + // Filter is the filter flag. Filter ) const ( + // RequestComplete is the completed request flag. RequestComplete uint8 = iota + // CantMultiplexConns is the multiplexed connections flag. CantMultiplexConns + // Overloaded is the overloaded flag. Overloaded + // UnknownRole is the unknown role flag. UnknownRole ) const ( - MaxConns string = "MAX_CONNS" - MaxRequests string = "MAX_REQS" + // MaxConns is the maximum connections flag. + MaxConns string = "MAX_CONNS" + // MaxRequests is the maximum requests flag. + MaxRequests string = "MAX_REQS" + // MultiplexConns is the multiplex connections flag. MultiplexConns string = "MPXS_CONNS" ) diff --git a/middleware/fastcgi/fcgiclient_test.go b/middleware/fastcgi/fcgiclient_test.go index 1abaf10fc..6ed37bb4a 100644 --- a/middleware/fastcgi/fcgiclient_test.go +++ b/middleware/fastcgi/fcgiclient_test.go @@ -193,8 +193,8 @@ func generateRandFile(size int) (p string, m string) { func DisabledTest(t *testing.T) { // TODO: test chunked reader - t_ = t + rand.Seed(time.Now().UTC().UnixNano()) // server diff --git a/middleware/fileserver_test.go b/middleware/fileserver_test.go index c9434a7ad..0ce454bb1 100644 --- a/middleware/fileserver_test.go +++ b/middleware/fileserver_test.go @@ -11,7 +11,7 @@ import ( ) var testDir = filepath.Join(os.TempDir(), "caddy_testdir") -var customErr = errors.New("Custom Error") +var ErrCustom = errors.New("Custom Error") // testFiles is a map with relative paths to test files as keys and file content as values. // The map represents the following structure: @@ -32,8 +32,8 @@ var testFiles = map[string]string{ // TestServeHTTP covers positive scenarios when serving files. func TestServeHTTP(t *testing.T) { - beforeServeHttpTest(t) - defer afterServeHttpTest(t) + beforeServeHTTPTest(t) + defer afterServeHTTPTest(t) fileserver := FileServer(http.Dir(testDir), []string{"hidden.html"}) @@ -137,8 +137,8 @@ func TestServeHTTP(t *testing.T) { } -// beforeServeHttpTest creates a test directory with the structure, defined in the variable testFiles -func beforeServeHttpTest(t *testing.T) { +// beforeServeHTTPTest creates a test directory with the structure, defined in the variable testFiles +func beforeServeHTTPTest(t *testing.T) { // make the root test dir err := os.Mkdir(testDir, os.ModePerm) if err != nil { @@ -176,8 +176,8 @@ func beforeServeHttpTest(t *testing.T) { } -// afterServeHttpTest removes the test dir and all its content -func afterServeHttpTest(t *testing.T) { +// afterServeHTTPTest removes the test dir and all its content +func afterServeHTTPTest(t *testing.T) { // cleans up everything under the test dir. No need to clean the individual files. err := os.RemoveAll(testDir) if err != nil { @@ -232,9 +232,9 @@ func TestServeHTTPFailingFS(t *testing.T) { expectedErr: os.ErrPermission, }, { - fsErr: customErr, + fsErr: ErrCustom, expectedStatus: http.StatusServiceUnavailable, - expectedErr: customErr, + expectedErr: ErrCustom, expectedHeaders: map[string]string{"Retry-After": "5"}, }, } @@ -293,9 +293,9 @@ func TestServeHTTPFailingStat(t *testing.T) { expectedErr: os.ErrPermission, }, { - statErr: customErr, + statErr: ErrCustom, expectedStatus: http.StatusInternalServerError, - expectedErr: customErr, + expectedErr: ErrCustom, }, } diff --git a/middleware/gzip/filter.go b/middleware/gzip/filter.go index 7871112f5..f4039da35 100644 --- a/middleware/gzip/filter.go +++ b/middleware/gzip/filter.go @@ -32,7 +32,7 @@ type ExtFilter struct { Exts Set } -// extWildCard is the wildcard for extensions. +// ExtWildCard is the wildcard for extensions. const ExtWildCard = "*" // ShouldCompress checks if the request file extension matches any diff --git a/middleware/log/log.go b/middleware/log/log.go index f2fbb4217..feb6182ad 100644 --- a/middleware/log/log.go +++ b/middleware/log/log.go @@ -51,9 +51,14 @@ type Rule struct { } const ( - DefaultLogFilename = "access.log" - CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{method} {uri} {proto}" {status} {size}` + // DefaultLogFilename is the default log filename. + DefaultLogFilename = "access.log" + // CommonLogFormat is the common log format. + CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{method} {uri} {proto}" {status} {size}` + // CommonLogEmptyValue is the common empty log value. CommonLogEmptyValue = "-" - CombinedLogFormat = CommonLogFormat + ` "{>Referer}" "{>User-Agent}"` - DefaultLogFormat = CommonLogFormat + // CombinedLogFormat is the combined log format. + CombinedLogFormat = CommonLogFormat + ` "{>Referer}" "{>User-Agent}"` + // DefaultLogFormat is the default log format. + DefaultLogFormat = CommonLogFormat ) diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index 65f22d66d..dc4083b7e 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -14,10 +14,13 @@ import ( ) const ( - DefaultTemplate = "defaultTemplate" + // DefaultTemplate is the default template. + DefaultTemplate = "defaultTemplate" + // DefaultStaticDir is the default static directory. DefaultStaticDir = "generated_site" ) +// Data represents a markdown document. type Data struct { middleware.Context Doc map[string]string diff --git a/middleware/markdown/renderer.go b/middleware/markdown/renderer.go index 5a749079a..44c0163d9 100644 --- a/middleware/markdown/renderer.go +++ b/middleware/markdown/renderer.go @@ -4,20 +4,27 @@ import ( "bytes" ) +// SummaryRenderer represents a summary renderer. type SummaryRenderer struct{} // Block-level callbacks +// BlockCode is the code tag callback. func (r SummaryRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {} +// BlockQuote is the quote tag callback. func (r SummaryRenderer) BlockQuote(out *bytes.Buffer, text []byte) {} +// BlockHtml is the HTML tag callback. func (r SummaryRenderer) BlockHtml(out *bytes.Buffer, text []byte) {} +// Header is the header tag callback. func (r SummaryRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) {} +// HRule is the horizontal rule tag callback. func (r SummaryRenderer) HRule(out *bytes.Buffer) {} +// List is the list tag callback. func (r SummaryRenderer) List(out *bytes.Buffer, text func() bool, flags int) { // TODO: This is not desired (we'd rather not write lists as part of summary), // but see this issue: https://github.com/russross/blackfriday/issues/189 @@ -28,8 +35,10 @@ func (r SummaryRenderer) List(out *bytes.Buffer, text func() bool, flags int) { out.Write([]byte{' '}) } +// ListItem is the list item tag callback. func (r SummaryRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {} +// Paragraph is the paragraph tag callback. func (r SummaryRenderer) Paragraph(out *bytes.Buffer, text func() bool) { marker := out.Len() if !text() { @@ -38,68 +47,93 @@ func (r SummaryRenderer) Paragraph(out *bytes.Buffer, text func() bool) { out.Write([]byte{' '}) } +// Table is the table tag callback. func (r SummaryRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {} +// TableRow is the table row tag callback. func (r SummaryRenderer) TableRow(out *bytes.Buffer, text []byte) {} +// TableHeaderCell is the table header cell tag callback. func (r SummaryRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) {} +// TableCell is the table cell tag callback. func (r SummaryRenderer) TableCell(out *bytes.Buffer, text []byte, flags int) {} +// Footnotes is the foot notes tag callback. func (r SummaryRenderer) Footnotes(out *bytes.Buffer, text func() bool) {} +// FootnoteItem is the footnote item tag callback. func (r SummaryRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) {} +// TitleBlock is the title tag callback. func (r SummaryRenderer) TitleBlock(out *bytes.Buffer, text []byte) {} // Span-level callbacks +// AutoLink is the autolink tag callback. func (r SummaryRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {} +// CodeSpan is the code span tag callback. func (r SummaryRenderer) CodeSpan(out *bytes.Buffer, text []byte) { out.Write([]byte("`")) out.Write(text) out.Write([]byte("`")) } +// DoubleEmphasis is the double emphasis tag callback. func (r SummaryRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { out.Write(text) } +// Emphasis is the emphasis tag callback. func (r SummaryRenderer) Emphasis(out *bytes.Buffer, text []byte) { out.Write(text) } +// Image is the image tag callback. func (r SummaryRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {} +// LineBreak is the line break tag callback. func (r SummaryRenderer) LineBreak(out *bytes.Buffer) {} +// Link is the link tag callback. func (r SummaryRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { out.Write(content) } + +// RawHtmlTag is the raw HTML tag callback. func (r SummaryRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) {} +// TripleEmphasis is the triple emphasis tag callback. func (r SummaryRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) { out.Write(text) } + +// StrikeThrough is the strikethrough tag callback. func (r SummaryRenderer) StrikeThrough(out *bytes.Buffer, text []byte) {} +// FootnoteRef is the footnote ref tag callback. func (r SummaryRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {} // Low-level callbacks +// Entity callback. func (r SummaryRenderer) Entity(out *bytes.Buffer, entity []byte) { out.Write(entity) } +// NormalText callback. func (r SummaryRenderer) NormalText(out *bytes.Buffer, text []byte) { out.Write(text) } // Header and footer +// DocumentHeader callback. func (r SummaryRenderer) DocumentHeader(out *bytes.Buffer) {} +// DocumentFooter callback. func (r SummaryRenderer) DocumentFooter(out *bytes.Buffer) {} +// GetFlags returns zero. func (r SummaryRenderer) GetFlags() int { return 0 } diff --git a/server/server.go b/server/server.go index 15128996f..c72cdd0d1 100644 --- a/server/server.go +++ b/server/server.go @@ -35,6 +35,7 @@ type Server struct { startChan chan struct{} // used to block until server is finished starting } +// ListenerFile represents a listener. type ListenerFile interface { net.Listener File() (*os.File, error)