Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
47c5b6c9
Commit
47c5b6c9
authored
Nov 05, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #305 from buddhamagnet/refactor/lint-vet
Lint pacification
parents
7a159ad9
e23af5e9
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
125 additions
and
39 deletions
+125
-39
caddy/caddy.go
caddy/caddy.go
+7
-3
caddy/caddyfile/json.go
caddy/caddyfile/json.go
+2
-0
caddy/config.go
caddy/config.go
+1
-1
caddy/helpers.go
caddy/helpers.go
+1
-1
caddy/letsencrypt/letsencrypt.go
caddy/letsencrypt/letsencrypt.go
+6
-6
caddy/letsencrypt/storage.go
caddy/letsencrypt/storage.go
+1
-1
caddy/parse/parse.go
caddy/parse/parse.go
+2
-2
caddy/restart.go
caddy/restart.go
+1
-1
caddy/setup/bindhost.go
caddy/setup/bindhost.go
+1
-0
caddy/setup/root.go
caddy/setup/root.go
+1
-0
caddy/setup/startupshutdown.go
caddy/setup/startupshutdown.go
+2
-0
caddy/setup/tls.go
caddy/setup/tls.go
+1
-0
middleware/basicauth/basicauth.go
middleware/basicauth/basicauth.go
+2
-1
middleware/browse/browse_test.go
middleware/browse/browse_test.go
+2
-2
middleware/fastcgi/fastcgi.go
middleware/fastcgi/fastcgi.go
+1
-1
middleware/fastcgi/fcgiclient.go
middleware/fastcgi/fcgiclient.go
+33
-2
middleware/fastcgi/fcgiclient_test.go
middleware/fastcgi/fcgiclient_test.go
+1
-1
middleware/fileserver_test.go
middleware/fileserver_test.go
+11
-11
middleware/gzip/filter.go
middleware/gzip/filter.go
+1
-1
middleware/log/log.go
middleware/log/log.go
+9
-4
middleware/markdown/process.go
middleware/markdown/process.go
+4
-1
middleware/markdown/renderer.go
middleware/markdown/renderer.go
+34
-0
server/server.go
server/server.go
+1
-0
No files found.
caddy/caddy.go
View file @
47c5b6c9
...
@@ -37,7 +37,8 @@ import (
...
@@ -37,7 +37,8 @@ import (
// Configurable application parameters
// Configurable application parameters
var
(
var
(
// The name and version of the application.
// The name and version of the application.
AppName
,
AppVersion
string
AppName
string
AppVersion
string
// If true, initialization will not show any informative output.
// If true, initialization will not show any informative output.
Quiet
bool
Quiet
bool
...
@@ -53,9 +54,9 @@ var (
...
@@ -53,9 +54,9 @@ var (
// caddyfileMu protects caddyfile during changes
// caddyfileMu protects caddyfile during changes
caddyfileMu
sync
.
Mutex
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
// 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 is a list of all the currently-listening servers
servers
[]
*
server
.
Server
servers
[]
*
server
.
Server
...
@@ -74,8 +75,11 @@ var (
...
@@ -74,8 +75,11 @@ var (
)
)
const
(
const
(
// DefaultHost is the default host.
DefaultHost
=
"0.0.0.0"
DefaultHost
=
"0.0.0.0"
// DefaultPort is the default port.
DefaultPort
=
"2015"
DefaultPort
=
"2015"
// DefaultRoot is the default root folder.
DefaultRoot
=
"."
DefaultRoot
=
"."
)
)
...
...
caddy/caddyfile/json.go
View file @
47c5b6c9
...
@@ -155,8 +155,10 @@ func jsonToText(scope interface{}, depth int) string {
...
@@ -155,8 +155,10 @@ func jsonToText(scope interface{}, depth int) string {
return
result
return
result
}
}
// Caddyfile encapsulates a slice of ServerBlocks.
type
Caddyfile
[]
ServerBlock
type
Caddyfile
[]
ServerBlock
// ServerBlock represents a server block.
type
ServerBlock
struct
{
type
ServerBlock
struct
{
Hosts
[]
string
`json:"hosts"`
Hosts
[]
string
`json:"hosts"`
Body
map
[
string
]
interface
{}
`json:"body"`
Body
map
[
string
]
interface
{}
`json:"body"`
...
...
caddy/config.go
View file @
47c5b6c9
...
@@ -280,7 +280,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) {
...
@@ -280,7 +280,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) {
// change them to 80 or 443 respectively. If a hostname fails to
// change them to 80 or 443 respectively. If a hostname fails to
// resolve, that host can still be served but will be listening on
// resolve, that host can still be served but will be listening on
// the wildcard host instead. This function takes care of this for you.
// 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
bindHost
:=
conf
.
BindHost
// TODO: Do we even need the port? Maybe we just need to look up the host.
// TODO: Do we even need the port? Maybe we just need to look up the host.
...
...
caddy/helpers.go
View file @
47c5b6c9
...
@@ -67,5 +67,5 @@ func (c CaddyfileInput) Body() []byte { return c.Contents }
...
@@ -67,5 +67,5 @@ func (c CaddyfileInput) Body() []byte { return c.Contents }
// Path returns c.Filepath.
// Path returns c.Filepath.
func
(
c
CaddyfileInput
)
Path
()
string
{
return
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
}
func
(
c
CaddyfileInput
)
IsFile
()
bool
{
return
c
.
RealFile
}
caddy/letsencrypt/letsencrypt.go
View file @
47c5b6c9
...
@@ -398,9 +398,9 @@ func otherHostHasScheme(allConfigs []server.Config, cfgIndex int, scheme string)
...
@@ -398,9 +398,9 @@ func otherHostHasScheme(allConfigs []server.Config, cfgIndex int, scheme string)
// be the HTTPS configuration. The returned configuration is set
// be the HTTPS configuration. The returned configuration is set
// to listen on the "http" port (port 80).
// to listen on the "http" port (port 80).
func
redirPlaintextHost
(
cfg
server
.
Config
)
server
.
Config
{
func
redirPlaintextHost
(
cfg
server
.
Config
)
server
.
Config
{
toU
rl
:=
"https://"
+
cfg
.
Host
toU
RL
:=
"https://"
+
cfg
.
Host
if
cfg
.
Port
!=
"https"
&&
cfg
.
Port
!=
"http"
{
if
cfg
.
Port
!=
"https"
&&
cfg
.
Port
!=
"http"
{
toU
rl
+=
":"
+
cfg
.
Port
toU
RL
+=
":"
+
cfg
.
Port
}
}
redirMidware
:=
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
redirMidware
:=
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
...
@@ -408,7 +408,7 @@ func redirPlaintextHost(cfg server.Config) server.Config {
...
@@ -408,7 +408,7 @@ func redirPlaintextHost(cfg server.Config) server.Config {
{
{
FromScheme
:
"http"
,
FromScheme
:
"http"
,
FromPath
:
"/"
,
FromPath
:
"/"
,
To
:
toU
rl
+
"{uri}"
,
To
:
toU
RL
+
"{uri}"
,
Code
:
http
.
StatusMovedPermanently
,
Code
:
http
.
StatusMovedPermanently
,
},
},
}}
}}
...
@@ -459,13 +459,13 @@ func Revoke(host string) error {
...
@@ -459,13 +459,13 @@ func Revoke(host string) error {
}
}
var
(
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
DefaultEmail
string
//
W
hether user has agreed to the Let's Encrypt SA
//
Agreed indicates w
hether user has agreed to the Let's Encrypt SA
Agreed
bool
Agreed
bool
//
T
he base URL to the CA's ACME endpoint
//
CAUrl represents t
he base URL to the CA's ACME endpoint
CAUrl
string
CAUrl
string
)
)
...
...
caddy/letsencrypt/storage.go
View file @
47c5b6c9
...
@@ -26,7 +26,7 @@ func (s Storage) Site(domain string) string {
...
@@ -26,7 +26,7 @@ func (s Storage) Site(domain string) string {
return
filepath
.
Join
(
s
.
Sites
(),
domain
)
return
filepath
.
Join
(
s
.
Sites
(),
domain
)
}
}
// CertFile returns the path to the certificate file for domain.
//
Site
CertFile returns the path to the certificate file for domain.
func
(
s
Storage
)
SiteCertFile
(
domain
string
)
string
{
func
(
s
Storage
)
SiteCertFile
(
domain
string
)
string
{
return
filepath
.
Join
(
s
.
Site
(
domain
),
domain
+
".crt"
)
return
filepath
.
Join
(
s
.
Site
(
domain
),
domain
+
".crt"
)
}
}
...
...
caddy/parse/parse.go
View file @
47c5b6c9
...
@@ -9,7 +9,7 @@ import "io"
...
@@ -9,7 +9,7 @@ import "io"
// otherwise we consider it a parse error. Server blocks are returned
// otherwise we consider it a parse error. Server blocks are returned
// in the order in which they appear.
// in the order in which they appear.
func
ServerBlocks
(
filename
string
,
input
io
.
Reader
,
checkDirectives
bool
)
([]
serverBlock
,
error
)
{
func
ServerBlocks
(
filename
string
,
input
io
.
Reader
,
checkDirectives
bool
)
([]
serverBlock
,
error
)
{
p
:=
parser
{
Dispenser
:
NewDispenser
(
filename
,
input
)
,
checkDirectives
:
checkDirectives
}
p
:=
parser
{
Dispenser
:
NewDispenser
(
filename
,
input
)}
blocks
,
err
:=
p
.
parseAll
()
blocks
,
err
:=
p
.
parseAll
()
return
blocks
,
err
return
blocks
,
err
}
}
...
@@ -26,6 +26,6 @@ func allTokens(input io.Reader) (tokens []token) {
...
@@ -26,6 +26,6 @@ func allTokens(input io.Reader) (tokens []token) {
return
return
}
}
//
S
et of directives that are valid (unordered). Populated
//
ValidDirectives is a s
et of directives that are valid (unordered). Populated
// by config package's init function.
// by config package's init function.
var
ValidDirectives
=
make
(
map
[
string
]
struct
{})
var
ValidDirectives
=
make
(
map
[
string
]
struct
{})
caddy/restart.go
View file @
47c5b6c9
...
@@ -94,7 +94,7 @@ func Restart(newCaddyfile Input) error {
...
@@ -94,7 +94,7 @@ func Restart(newCaddyfile Input) error {
answer
,
err
:=
ioutil
.
ReadAll
(
sigrpipe
)
answer
,
err
:=
ioutil
.
ReadAll
(
sigrpipe
)
if
err
!=
nil
||
len
(
answer
)
==
0
{
if
err
!=
nil
||
len
(
answer
)
==
0
{
log
.
Println
(
"restart: child failed to initialize; changes not applied"
)
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.
// Child process is listening now; we can stop all our servers here.
...
...
caddy/setup/bindhost.go
View file @
47c5b6c9
...
@@ -2,6 +2,7 @@ package setup
...
@@ -2,6 +2,7 @@ package setup
import
"github.com/mholt/caddy/middleware"
import
"github.com/mholt/caddy/middleware"
// BindHost sets the host to bind the listener to.
func
BindHost
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
BindHost
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
for
c
.
Next
()
{
for
c
.
Next
()
{
if
!
c
.
Args
(
&
c
.
BindHost
)
{
if
!
c
.
Args
(
&
c
.
BindHost
)
{
...
...
caddy/setup/root.go
View file @
47c5b6c9
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware"
)
)
// Root sets up the root file path of the server.
func
Root
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
Root
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
for
c
.
Next
()
{
for
c
.
Next
()
{
if
!
c
.
NextArg
()
{
if
!
c
.
NextArg
()
{
...
...
caddy/setup/startupshutdown.go
View file @
47c5b6c9
...
@@ -8,10 +8,12 @@ import (
...
@@ -8,10 +8,12 @@ import (
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware"
)
)
// Startup registers a startup callback to execute during server start.
func
Startup
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
Startup
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
return
nil
,
registerCallback
(
c
,
&
c
.
Startup
)
return
nil
,
registerCallback
(
c
,
&
c
.
Startup
)
}
}
// Shutdown registers a shutdown callback to execute during process exit.
func
Shutdown
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
Shutdown
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
return
nil
,
registerCallback
(
c
,
&
c
.
Shutdown
)
return
nil
,
registerCallback
(
c
,
&
c
.
Shutdown
)
}
}
...
...
caddy/setup/tls.go
View file @
47c5b6c9
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"github.com/mholt/caddy/server"
"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
)
{
func
TLS
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
if
c
.
Port
==
"http"
{
if
c
.
Port
==
"http"
{
c
.
TLS
.
Enabled
=
false
c
.
TLS
.
Enabled
=
false
...
...
middleware/basicauth/basicauth.go
View file @
47c5b6c9
...
@@ -78,7 +78,7 @@ type Rule struct {
...
@@ -78,7 +78,7 @@ type Rule struct {
Resources
[]
string
Resources
[]
string
}
}
// PasswordMatcher determines whether a password mathes a rule.
// PasswordMatcher determines whether a password mat
c
hes a rule.
type
PasswordMatcher
func
(
pw
string
)
bool
type
PasswordMatcher
func
(
pw
string
)
bool
var
(
var
(
...
@@ -86,6 +86,7 @@ var (
...
@@ -86,6 +86,7 @@ var (
htpasswordsMu
sync
.
Mutex
htpasswordsMu
sync
.
Mutex
)
)
// GetHtpasswdMatcher matches password rules.
func
GetHtpasswdMatcher
(
filename
,
username
,
siteRoot
string
)
(
PasswordMatcher
,
error
)
{
func
GetHtpasswdMatcher
(
filename
,
username
,
siteRoot
string
)
(
PasswordMatcher
,
error
)
{
filename
=
filepath
.
Join
(
siteRoot
,
filename
)
filename
=
filepath
.
Join
(
siteRoot
,
filename
)
htpasswordsMu
.
Lock
()
htpasswordsMu
.
Lock
()
...
...
middleware/browse/browse_test.go
View file @
47c5b6c9
...
@@ -223,7 +223,7 @@ func TestBrowseJson(t *testing.T) {
...
@@ -223,7 +223,7 @@ func TestBrowseJson(t *testing.T) {
listing
:=
Listing
{
Items
:
fileinfos
}
// this listing will be used for validation inside the tests
listing
:=
Listing
{
Items
:
fileinfos
}
// this listing will be used for validation inside the tests
tests
:=
[]
struct
{
tests
:=
[]
struct
{
QueryU
rl
string
QueryU
RL
string
SortBy
string
SortBy
string
OrderBy
string
OrderBy
string
Limit
int
Limit
int
...
@@ -263,7 +263,7 @@ func TestBrowseJson(t *testing.T) {
...
@@ -263,7 +263,7 @@ func TestBrowseJson(t *testing.T) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
var
marsh
[]
byte
var
marsh
[]
byte
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/photos"
+
test
.
QueryU
rl
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/photos"
+
test
.
QueryU
RL
,
nil
)
if
err
==
nil
&&
test
.
shouldErr
{
if
err
==
nil
&&
test
.
shouldErr
{
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
...
...
middleware/fastcgi/fastcgi.go
View file @
47c5b6c9
...
@@ -278,6 +278,6 @@ type Rule struct {
...
@@ -278,6 +278,6 @@ type Rule struct {
var
(
var
(
headerNameReplacer
=
strings
.
NewReplacer
(
" "
,
"_"
,
"-"
,
"_"
)
headerNameReplacer
=
strings
.
NewReplacer
(
" "
,
"_"
,
"-"
,
"_"
)
// ErrIndexMissingSplit describes an index configuration error.
ErrIndexMissingSplit
=
errors
.
New
(
"configured index file(s) must include split value"
)
ErrIndexMissingSplit
=
errors
.
New
(
"configured index file(s) must include split value"
)
)
)
middleware/fastcgi/fcgiclient.go
View file @
47c5b6c9
...
@@ -30,44 +30,75 @@ import (
...
@@ -30,44 +30,75 @@ import (
"sync"
"sync"
)
)
// FCGIListenSockFileno describes listen socket file number.
const
FCGIListenSockFileno
uint8
=
0
const
FCGIListenSockFileno
uint8
=
0
// FCGIHeaderLen describes header length.
const
FCGIHeaderLen
uint8
=
8
const
FCGIHeaderLen
uint8
=
8
// Version1 describes the version.
const
Version1
uint8
=
1
const
Version1
uint8
=
1
// FCGINullRequestID describes the null request ID.
const
FCGINullRequestID
uint8
=
0
const
FCGINullRequestID
uint8
=
0
// FCGIKeepConn describes keep connection mode.
const
FCGIKeepConn
uint8
=
1
const
FCGIKeepConn
uint8
=
1
const
doubleCRLF
=
"
\r\n\r\n
"
const
doubleCRLF
=
"
\r\n\r\n
"
const
(
const
(
// BeginRequest is the begin request flag.
BeginRequest
uint8
=
iota
+
1
BeginRequest
uint8
=
iota
+
1
// AbortRequest is the abort request flag.
AbortRequest
AbortRequest
// EndRequest is the end request flag.
EndRequest
EndRequest
// Params is the parameters flag.
Params
Params
// Stdin is the standard input flag.
Stdin
Stdin
// Stdout is the standard output flag.
Stdout
Stdout
// Stderr is the standard error flag.
Stderr
Stderr
// Data is the data flag.
Data
Data
// GetValues is the get values flag.
GetValues
GetValues
// GetValuesResult is the get values result flag.
GetValuesResult
GetValuesResult
// UnknownType is the unknown type flag.
UnknownType
UnknownType
// MaxType is the maximum type flag.
MaxType
=
UnknownType
MaxType
=
UnknownType
)
)
const
(
const
(
// Responder is the responder flag.
Responder
uint8
=
iota
+
1
Responder
uint8
=
iota
+
1
// Authorizer is the authorizer flag.
Authorizer
Authorizer
// Filter is the filter flag.
Filter
Filter
)
)
const
(
const
(
// RequestComplete is the completed request flag.
RequestComplete
uint8
=
iota
RequestComplete
uint8
=
iota
// CantMultiplexConns is the multiplexed connections flag.
CantMultiplexConns
CantMultiplexConns
// Overloaded is the overloaded flag.
Overloaded
Overloaded
// UnknownRole is the unknown role flag.
UnknownRole
UnknownRole
)
)
const
(
const
(
MaxConns
string
=
"MAX_CONNS"
// MaxConns is the maximum connections flag.
MaxRequests
string
=
"MAX_REQS"
MaxConns
string
=
"MAX_CONNS"
// MaxRequests is the maximum requests flag.
MaxRequests
string
=
"MAX_REQS"
// MultiplexConns is the multiplex connections flag.
MultiplexConns
string
=
"MPXS_CONNS"
MultiplexConns
string
=
"MPXS_CONNS"
)
)
...
...
middleware/fastcgi/fcgiclient_test.go
View file @
47c5b6c9
...
@@ -193,8 +193,8 @@ func generateRandFile(size int) (p string, m string) {
...
@@ -193,8 +193,8 @@ func generateRandFile(size int) (p string, m string) {
func
DisabledTest
(
t
*
testing
.
T
)
{
func
DisabledTest
(
t
*
testing
.
T
)
{
// TODO: test chunked reader
// TODO: test chunked reader
t_
=
t
t_
=
t
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
// server
// server
...
...
middleware/fileserver_test.go
View file @
47c5b6c9
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
)
)
var
testDir
=
filepath
.
Join
(
os
.
TempDir
(),
"caddy_testdir"
)
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.
// testFiles is a map with relative paths to test files as keys and file content as values.
// The map represents the following structure:
// The map represents the following structure:
...
@@ -32,8 +32,8 @@ var testFiles = map[string]string{
...
@@ -32,8 +32,8 @@ var testFiles = map[string]string{
// TestServeHTTP covers positive scenarios when serving files.
// TestServeHTTP covers positive scenarios when serving files.
func
TestServeHTTP
(
t
*
testing
.
T
)
{
func
TestServeHTTP
(
t
*
testing
.
T
)
{
beforeServeH
ttp
Test
(
t
)
beforeServeH
TTP
Test
(
t
)
defer
afterServeH
ttp
Test
(
t
)
defer
afterServeH
TTP
Test
(
t
)
fileserver
:=
FileServer
(
http
.
Dir
(
testDir
),
[]
string
{
"hidden.html"
})
fileserver
:=
FileServer
(
http
.
Dir
(
testDir
),
[]
string
{
"hidden.html"
})
...
@@ -137,8 +137,8 @@ func TestServeHTTP(t *testing.T) {
...
@@ -137,8 +137,8 @@ func TestServeHTTP(t *testing.T) {
}
}
// beforeServeH
ttp
Test creates a test directory with the structure, defined in the variable testFiles
// beforeServeH
TTP
Test creates a test directory with the structure, defined in the variable testFiles
func
beforeServeH
ttp
Test
(
t
*
testing
.
T
)
{
func
beforeServeH
TTP
Test
(
t
*
testing
.
T
)
{
// make the root test dir
// make the root test dir
err
:=
os
.
Mkdir
(
testDir
,
os
.
ModePerm
)
err
:=
os
.
Mkdir
(
testDir
,
os
.
ModePerm
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -176,8 +176,8 @@ func beforeServeHttpTest(t *testing.T) {
...
@@ -176,8 +176,8 @@ func beforeServeHttpTest(t *testing.T) {
}
}
// afterServeH
ttp
Test removes the test dir and all its content
// afterServeH
TTP
Test removes the test dir and all its content
func
afterServeH
ttp
Test
(
t
*
testing
.
T
)
{
func
afterServeH
TTP
Test
(
t
*
testing
.
T
)
{
// cleans up everything under the test dir. No need to clean the individual files.
// cleans up everything under the test dir. No need to clean the individual files.
err
:=
os
.
RemoveAll
(
testDir
)
err
:=
os
.
RemoveAll
(
testDir
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -232,9 +232,9 @@ func TestServeHTTPFailingFS(t *testing.T) {
...
@@ -232,9 +232,9 @@ func TestServeHTTPFailingFS(t *testing.T) {
expectedErr
:
os
.
ErrPermission
,
expectedErr
:
os
.
ErrPermission
,
},
},
{
{
fsErr
:
customErr
,
fsErr
:
ErrCustom
,
expectedStatus
:
http
.
StatusServiceUnavailable
,
expectedStatus
:
http
.
StatusServiceUnavailable
,
expectedErr
:
customErr
,
expectedErr
:
ErrCustom
,
expectedHeaders
:
map
[
string
]
string
{
"Retry-After"
:
"5"
},
expectedHeaders
:
map
[
string
]
string
{
"Retry-After"
:
"5"
},
},
},
}
}
...
@@ -293,9 +293,9 @@ func TestServeHTTPFailingStat(t *testing.T) {
...
@@ -293,9 +293,9 @@ func TestServeHTTPFailingStat(t *testing.T) {
expectedErr
:
os
.
ErrPermission
,
expectedErr
:
os
.
ErrPermission
,
},
},
{
{
statErr
:
customErr
,
statErr
:
ErrCustom
,
expectedStatus
:
http
.
StatusInternalServerError
,
expectedStatus
:
http
.
StatusInternalServerError
,
expectedErr
:
customErr
,
expectedErr
:
ErrCustom
,
},
},
}
}
...
...
middleware/gzip/filter.go
View file @
47c5b6c9
...
@@ -32,7 +32,7 @@ type ExtFilter struct {
...
@@ -32,7 +32,7 @@ type ExtFilter struct {
Exts
Set
Exts
Set
}
}
//
e
xtWildCard is the wildcard for extensions.
//
E
xtWildCard is the wildcard for extensions.
const
ExtWildCard
=
"*"
const
ExtWildCard
=
"*"
// ShouldCompress checks if the request file extension matches any
// ShouldCompress checks if the request file extension matches any
...
...
middleware/log/log.go
View file @
47c5b6c9
...
@@ -51,9 +51,14 @@ type Rule struct {
...
@@ -51,9 +51,14 @@ type Rule struct {
}
}
const
(
const
(
DefaultLogFilename
=
"access.log"
// DefaultLogFilename is the default log filename.
CommonLogFormat
=
`{remote} `
+
CommonLogEmptyValue
+
` [{when}] "{method} {uri} {proto}" {status} {size}`
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
=
"-"
CommonLogEmptyValue
=
"-"
CombinedLogFormat
=
CommonLogFormat
+
` "{>Referer}" "{>User-Agent}"`
// CombinedLogFormat is the combined log format.
DefaultLogFormat
=
CommonLogFormat
CombinedLogFormat
=
CommonLogFormat
+
` "{>Referer}" "{>User-Agent}"`
// DefaultLogFormat is the default log format.
DefaultLogFormat
=
CommonLogFormat
)
)
middleware/markdown/process.go
View file @
47c5b6c9
...
@@ -14,10 +14,13 @@ import (
...
@@ -14,10 +14,13 @@ import (
)
)
const
(
const
(
DefaultTemplate
=
"defaultTemplate"
// DefaultTemplate is the default template.
DefaultTemplate
=
"defaultTemplate"
// DefaultStaticDir is the default static directory.
DefaultStaticDir
=
"generated_site"
DefaultStaticDir
=
"generated_site"
)
)
// Data represents a markdown document.
type
Data
struct
{
type
Data
struct
{
middleware
.
Context
middleware
.
Context
Doc
map
[
string
]
string
Doc
map
[
string
]
string
...
...
middleware/markdown/renderer.go
View file @
47c5b6c9
...
@@ -4,20 +4,27 @@ import (
...
@@ -4,20 +4,27 @@ import (
"bytes"
"bytes"
)
)
// SummaryRenderer represents a summary renderer.
type
SummaryRenderer
struct
{}
type
SummaryRenderer
struct
{}
// Block-level callbacks
// Block-level callbacks
// BlockCode is the code tag callback.
func
(
r
SummaryRenderer
)
BlockCode
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
lang
string
)
{}
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
)
{}
func
(
r
SummaryRenderer
)
BlockQuote
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// BlockHtml is the HTML tag callback.
func
(
r
SummaryRenderer
)
BlockHtml
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
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
)
{}
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
)
{}
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
)
{
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),
// 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
// 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) {
...
@@ -28,8 +35,10 @@ func (r SummaryRenderer) List(out *bytes.Buffer, text func() bool, flags int) {
out
.
Write
([]
byte
{
' '
})
out
.
Write
([]
byte
{
' '
})
}
}
// ListItem is the list item tag callback.
func
(
r
SummaryRenderer
)
ListItem
(
out
*
bytes
.
Buffer
,
text
[]
byte
,
flags
int
)
{}
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
)
{
func
(
r
SummaryRenderer
)
Paragraph
(
out
*
bytes
.
Buffer
,
text
func
()
bool
)
{
marker
:=
out
.
Len
()
marker
:=
out
.
Len
()
if
!
text
()
{
if
!
text
()
{
...
@@ -38,68 +47,93 @@ func (r SummaryRenderer) Paragraph(out *bytes.Buffer, text func() bool) {
...
@@ -38,68 +47,93 @@ func (r SummaryRenderer) Paragraph(out *bytes.Buffer, text func() bool) {
out
.
Write
([]
byte
{
' '
})
out
.
Write
([]
byte
{
' '
})
}
}
// Table is the table tag callback.
func
(
r
SummaryRenderer
)
Table
(
out
*
bytes
.
Buffer
,
header
[]
byte
,
body
[]
byte
,
columnData
[]
int
)
{}
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
)
{}
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
)
{}
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
)
{}
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
)
{}
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
)
{}
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
)
{}
func
(
r
SummaryRenderer
)
TitleBlock
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
// Span-level callbacks
// Span-level callbacks
// AutoLink is the autolink tag callback.
func
(
r
SummaryRenderer
)
AutoLink
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
kind
int
)
{}
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
)
{
func
(
r
SummaryRenderer
)
CodeSpan
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
([]
byte
(
"`"
))
out
.
Write
([]
byte
(
"`"
))
out
.
Write
(
text
)
out
.
Write
(
text
)
out
.
Write
([]
byte
(
"`"
))
out
.
Write
([]
byte
(
"`"
))
}
}
// DoubleEmphasis is the double emphasis tag callback.
func
(
r
SummaryRenderer
)
DoubleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
SummaryRenderer
)
DoubleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
out
.
Write
(
text
)
}
}
// Emphasis is the emphasis tag callback.
func
(
r
SummaryRenderer
)
Emphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
SummaryRenderer
)
Emphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
out
.
Write
(
text
)
}
}
// Image is the image tag callback.
func
(
r
SummaryRenderer
)
Image
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
alt
[]
byte
)
{}
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
)
{}
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
)
{
func
(
r
SummaryRenderer
)
Link
(
out
*
bytes
.
Buffer
,
link
[]
byte
,
title
[]
byte
,
content
[]
byte
)
{
out
.
Write
(
content
)
out
.
Write
(
content
)
}
}
// RawHtmlTag is the raw HTML tag callback.
func
(
r
SummaryRenderer
)
RawHtmlTag
(
out
*
bytes
.
Buffer
,
tag
[]
byte
)
{}
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
)
{
func
(
r
SummaryRenderer
)
TripleEmphasis
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
out
.
Write
(
text
)
}
}
// StrikeThrough is the strikethrough tag callback.
func
(
r
SummaryRenderer
)
StrikeThrough
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{}
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
)
{}
func
(
r
SummaryRenderer
)
FootnoteRef
(
out
*
bytes
.
Buffer
,
ref
[]
byte
,
id
int
)
{}
// Low-level callbacks
// Low-level callbacks
// Entity callback.
func
(
r
SummaryRenderer
)
Entity
(
out
*
bytes
.
Buffer
,
entity
[]
byte
)
{
func
(
r
SummaryRenderer
)
Entity
(
out
*
bytes
.
Buffer
,
entity
[]
byte
)
{
out
.
Write
(
entity
)
out
.
Write
(
entity
)
}
}
// NormalText callback.
func
(
r
SummaryRenderer
)
NormalText
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
func
(
r
SummaryRenderer
)
NormalText
(
out
*
bytes
.
Buffer
,
text
[]
byte
)
{
out
.
Write
(
text
)
out
.
Write
(
text
)
}
}
// Header and footer
// Header and footer
// DocumentHeader callback.
func
(
r
SummaryRenderer
)
DocumentHeader
(
out
*
bytes
.
Buffer
)
{}
func
(
r
SummaryRenderer
)
DocumentHeader
(
out
*
bytes
.
Buffer
)
{}
// DocumentFooter callback.
func
(
r
SummaryRenderer
)
DocumentFooter
(
out
*
bytes
.
Buffer
)
{}
func
(
r
SummaryRenderer
)
DocumentFooter
(
out
*
bytes
.
Buffer
)
{}
// GetFlags returns zero.
func
(
r
SummaryRenderer
)
GetFlags
()
int
{
return
0
}
func
(
r
SummaryRenderer
)
GetFlags
()
int
{
return
0
}
server/server.go
View file @
47c5b6c9
...
@@ -35,6 +35,7 @@ type Server struct {
...
@@ -35,6 +35,7 @@ type Server struct {
startChan
chan
struct
{}
// used to block until server is finished starting
startChan
chan
struct
{}
// used to block until server is finished starting
}
}
// ListenerFile represents a listener.
type
ListenerFile
interface
{
type
ListenerFile
interface
{
net
.
Listener
net
.
Listener
File
()
(
*
os
.
File
,
error
)
File
()
(
*
os
.
File
,
error
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment