Skip to content

Commit

Permalink
Remove dead code, do struct alignment, simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Gajewski committed Oct 25, 2016
1 parent c4d64a4 commit 8cc3416
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 99 deletions.
4 changes: 2 additions & 2 deletions caddyfile/dispenser_test.go
Expand Up @@ -64,7 +64,7 @@ func TestDispenser_NextArg(t *testing.T) {
}

assertNextArg := func(expectedVal string, loadAnother bool, expectedCursor int) {
if d.NextArg() != true {
if !d.NextArg() {
t.Error("NextArg(): Should load next argument but got false instead")
}
if d.cursor != expectedCursor {
Expand All @@ -74,7 +74,7 @@ func TestDispenser_NextArg(t *testing.T) {
t.Errorf("Val(): Expected '%s' but got '%s'", expectedVal, val)
}
if !loadAnother {
if d.NextArg() != false {
if d.NextArg() {
t.Fatalf("NextArg(): Should NOT load another argument, but got true instead (val: '%s')", d.Val())
}
if d.cursor != expectedCursor {
Expand Down
18 changes: 4 additions & 14 deletions caddyfile/parse.go
Expand Up @@ -16,8 +16,7 @@ import (
// pass in nil instead.
func Parse(filename string, input io.Reader, validDirectives []string) ([]ServerBlock, error) {
p := parser{Dispenser: NewDispenser(filename, input), validDirectives: validDirectives}
blocks, err := p.parseAll()
return blocks, err
return p.parseAll()
}

// allTokens lexes the entire input, but does not parse it.
Expand Down Expand Up @@ -62,12 +61,7 @@ func (p *parser) parseAll() ([]ServerBlock, error) {
func (p *parser) parseOne() error {
p.block = ServerBlock{Tokens: make(map[string][]Token)}

err := p.begin()
if err != nil {
return err
}

return nil
return p.begin()
}

func (p *parser) begin() error {
Expand All @@ -76,6 +70,7 @@ func (p *parser) begin() error {
}

err := p.addresses()

if err != nil {
return err
}
Expand All @@ -86,12 +81,7 @@ func (p *parser) begin() error {
return nil
}

err = p.blockContents()
if err != nil {
return err
}

return nil
return p.blockContents()
}

func (p *parser) addresses() error {
Expand Down
2 changes: 1 addition & 1 deletion caddyhttp/browse/browse.go
Expand Up @@ -101,12 +101,12 @@ func (l Listing) BreadcrumbMap() map[string]string {

// FileInfo is the info about a particular file or directory
type FileInfo struct {
IsDir bool
Name string
Size int64
URL string
ModTime time.Time
Mode os.FileMode
IsDir bool
}

// HumanSize returns the size of the file as a human-readable string
Expand Down
24 changes: 0 additions & 24 deletions caddyhttp/fastcgi/fcgiclient.go
Expand Up @@ -44,7 +44,6 @@ 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.
Expand Down Expand Up @@ -261,29 +260,6 @@ func (c *FCGIClient) writePairs(recType uint8, pairs map[string]string) error {
return nil
}

func readSize(s []byte) (uint32, int) {
if len(s) == 0 {
return 0, 0
}
size, n := uint32(s[0]), 1
if size&(1<<7) != 0 {
if len(s) < 4 {
return 0, 0
}
n = 4
size = binary.BigEndian.Uint32(s)
size &^= 1 << 31
}
return size, n
}

func readString(s []byte, size uint32) string {
if size > uint32(len(s)) {
return ""
}
return string(s[:size])
}

func encodeSize(b []byte, size uint32) int {
if size > 127 {
size |= 1 << 31
Expand Down
2 changes: 1 addition & 1 deletion caddyhttp/fastcgi/fcgiclient_test.go
Expand Up @@ -155,7 +155,7 @@ func sendFcgi(reqType int, fcgiParams map[string]string, data []byte, posts map[
fcgi.Close()
time.Sleep(1 * time.Second)

if bytes.Index(content, []byte("FAILED")) >= 0 {
if bytes.Contains(content, []byte("FAILED")) {
globalt.Error("Server return failed message")
}

Expand Down
2 changes: 1 addition & 1 deletion caddyhttp/markdown/markdown.go
Expand Up @@ -144,7 +144,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
}

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Set("Content-Length", strconv.FormatInt(int64(len(html)), 10))
w.Header().Set("Content-Length", strconv.Itoa(len(html)))
httpserver.SetLastModifiedHeader(w, lastModTime)
if r.Method == http.MethodGet {
w.Write(html)
Expand Down
12 changes: 6 additions & 6 deletions caddyhttp/proxy/proxy.go
Expand Up @@ -46,17 +46,17 @@ type UpstreamHostDownFunc func(*UpstreamHost) bool

// UpstreamHost represents a single proxy upstream
type UpstreamHost struct {
Conns int64 // must be first field to be 64-bit aligned on 32-bit systems
Conns int64 // must be first field to be 64-bit aligned on 32-bit systems
MaxConns int64
Name string // hostname of this upstream host
ReverseProxy *ReverseProxy
Fails int32
FailTimeout time.Duration
Unhealthy bool
UpstreamHeaders http.Header
DownstreamHeaders http.Header
FailTimeout time.Duration
CheckDown UpstreamHostDownFunc
WithoutPathPrefix string
MaxConns int64
ReverseProxy *ReverseProxy
Fails int32
Unhealthy bool
}

// Down checks whether the upstream host is down or not.
Expand Down
31 changes: 15 additions & 16 deletions caddyhttp/proxy/upstream.go
Expand Up @@ -21,27 +21,26 @@ var (
)

type staticUpstream struct {
from string
upstreamHeaders http.Header
downstreamHeaders http.Header
Hosts HostPool
Policy Policy
KeepAlive int
insecureSkipVerify bool

FailTimeout time.Duration
MaxFails int32
TryDuration time.Duration
TryInterval time.Duration
MaxConns int64
HealthCheck struct {
from string
upstreamHeaders http.Header
downstreamHeaders http.Header
Hosts HostPool
Policy Policy
KeepAlive int
FailTimeout time.Duration
TryDuration time.Duration
TryInterval time.Duration
MaxConns int64
HealthCheck struct {
Client http.Client
Path string
Interval time.Duration
Timeout time.Duration
}
WithoutPathPrefix string
IgnoredSubPaths []string
WithoutPathPrefix string
IgnoredSubPaths []string
insecureSkipVerify bool
MaxFails int32
}

// NewStaticUpstreams parses the configuration input and sets up
Expand Down
5 changes: 1 addition & 4 deletions caddyhttp/rewrite/rewrite.go
Expand Up @@ -216,10 +216,7 @@ func (r *ComplexRule) matchExt(rPath string) bool {
}
}

if mustUse {
return false
}
return true
return !mustUse
}

func (r *ComplexRule) regexpMatches(rPath string) []string {
Expand Down
23 changes: 1 addition & 22 deletions caddytls/config.go
Expand Up @@ -217,7 +217,7 @@ func (c *Config) StorageFor(caURL string) (Storage, error) {
// MakeTLSConfig reduces configs into a single tls.Config.
// If TLS is to be disabled, a nil tls.Config will be returned.
func MakeTLSConfig(configs []*Config) (*tls.Config, error) {
if configs == nil || len(configs) == 0 {
if len(configs) == 0 {
return nil, nil
}

Expand Down Expand Up @@ -418,27 +418,6 @@ var supportedCiphersMap = map[string]uint16{
"RSA-3DES-EDE-CBC-SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
}

// List of supported cipher suites in descending order of preference.
// Ordering is very important! Getting the wrong order will break
// mainstream clients, especially with HTTP/2.
//
// Note that TLS_FALLBACK_SCSV is not in this list since it is always
// added manually.
var supportedCiphers = []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
}

// List of all the ciphers we want to use by default
var defaultCiphers = []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
Expand Down
2 changes: 1 addition & 1 deletion caddytls/crypto_test.go
Expand Up @@ -120,7 +120,7 @@ func TestStandaloneTLSTicketKeyRotation(t *testing.T) {
t.Errorf("Expected TLS ticket keys in use: %d; Got instead: %d.", rounds, pkt.keysInUse)
return
}
if c.SessionTicketsDisabled == true {
if c.SessionTicketsDisabled {
t.Error("Session tickets have been disabled unexpectedly.")
return
}
Expand Down
2 changes: 0 additions & 2 deletions caddytls/handshake.go
Expand Up @@ -301,5 +301,3 @@ var failedIssuanceMu sync.RWMutex
// If this value is recent, do not make any on-demand certificate requests.
var lastIssueTime time.Time
var lastIssueTimeMu sync.Mutex

var errNoCert = errors.New("no certificate available")
6 changes: 1 addition & 5 deletions caddytls/user.go
Expand Up @@ -118,11 +118,7 @@ func getUser(storage Storage, email string) (User, error) {

// load their private key
user.key, err = loadPrivateKey(userData.Key)
if err != nil {
return user, err
}

return user, nil
return user, err
}

// saveUser persists a user's key and account registration
Expand Down

0 comments on commit 8cc3416

Please sign in to comment.