Skip to content

Commit

Permalink
Correct linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchenyun committed Apr 8, 2018
1 parent cfffc79 commit a64c39c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Proxy) AddHTTPHostRoute(ipPort, httpHost string, dest Target) {
// for any additional routes on ipPort.
//
// The ipPort is any valid net.Listen TCP address.
func (p *Proxy) AddHTTPHostMatchRoute(ipPort string, match Matcher, dest Target) (routeId int) {
func (p *Proxy) AddHTTPHostMatchRoute(ipPort string, match Matcher, dest Target) (routeID int) {
return p.addRoute(ipPort, httpHostMatch{match, dest})
}

Expand Down
4 changes: 2 additions & 2 deletions sni.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// with AddStopACMESearch.
//
// The ipPort is any valid net.Listen TCP address.
func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) (routeId int) {
func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) (routeID int) {
return p.AddSNIMatchRoute(ipPort, equals(sni), dest)
}

Expand All @@ -48,7 +48,7 @@ func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) (routeId int) {
// with AddStopACMESearch.
//
// The ipPort is any valid net.Listen TCP address.
func (p *Proxy) AddSNIMatchRoute(ipPort string, matcher Matcher, dest Target) (routeId int) {
func (p *Proxy) AddSNIMatchRoute(ipPort string, matcher Matcher, dest Target) (routeID int) {
cfg := p.configFor(ipPort)
if !cfg.stopACME {
if len(cfg.acmeTargets) == 0 {
Expand Down
24 changes: 12 additions & 12 deletions tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func equals(want string) Matcher {
// config contains the proxying state for one listener.
type config struct {
sync.Mutex // protect w of routes
nextRouteId int
nextRouteID int
routes map[int]route
acmeTargets []Target // accumulates targets that should be probed for acme.
stopACME bool // if true, AddSNIRoute doesn't add targets to acmeTargets.
}

func NewConfig() (cfg *config) {
func newConfig() (cfg *config) {
cfg = &config{}
cfg.routes = make(map[int]route)
cfg.nextRouteId = 1
cfg.nextRouteID = 1
return
}

Expand Down Expand Up @@ -132,12 +132,12 @@ func (p *Proxy) configFor(ipPort string) *config {
p.configs = make(map[string]*config)
}
if p.configs[ipPort] == nil {
p.configs[ipPort] = NewConfig()
p.configs[ipPort] = newConfig()
}
return p.configs[ipPort]
}

func (p *Proxy) addRoute(ipPort string, r route) (routeId int) {
func (p *Proxy) addRoute(ipPort string, r route) (routeID int) {
var cfg *config
if p.donec != nil {
// NOTE: Do not create config file if the server is listening.
Expand All @@ -149,33 +149,33 @@ func (p *Proxy) addRoute(ipPort string, r route) (routeId int) {
}
if cfg != nil {
cfg.Lock()
routeId = cfg.nextRouteId
cfg.nextRouteId++
cfg.routes[routeId] = r
routeID = cfg.nextRouteID
cfg.nextRouteID++
cfg.routes[routeID] = r
cfg.Unlock()
}
return
}

// AddRoute appends an always-matching route to the ipPort listener,
// directing any connection to dest. The added route's id is returned
// for future removal. If routeId is zero, the route is not registered.
// for future removal. If routeID is zero, the route is not registered.
//
// This is generally used as either the only rule (for simple TCP
// proxies), or as the final fallback rule for an ipPort.
//
// The ipPort is any valid net.Listen TCP address.
func (p *Proxy) AddRoute(ipPort string, dest Target) (routeId int) {
func (p *Proxy) AddRoute(ipPort string, dest Target) (routeID int) {
return p.addRoute(ipPort, fixedTarget{dest})
}

// RemoveRoute removes an existing route for ipPort. If the route is
// not found, this is an no-op.
//
// Both AddRoute and RemoveRoute is go-routine safe.
func (p *Proxy) RemoveRoute(ipPort string, routeId int) (err error) {
func (p *Proxy) RemoveRoute(ipPort string, routeID int) (err error) {
cfg := p.configFor(ipPort)
cfg.routes[routeId] = nil
cfg.routes[routeID] = nil
return
}

Expand Down
4 changes: 2 additions & 2 deletions tcpproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ func TestProxyRemoveRoute(t *testing.T) {

backBar := newLocalListener(t)
defer backBar.Close()
routeId := p.AddSNIRoute(testFrontAddr, "bar.com", To(backBar.Addr().String()))
routeID := p.AddSNIRoute(testFrontAddr, "bar.com", To(backBar.Addr().String()))

msg := clientHelloRecord(t, "bar.com")
testRouteToBackend(t, front, backBar, msg)

p.RemoveRoute(testFrontAddr, routeId)
p.RemoveRoute(testFrontAddr, routeID)
<-testNotRouteToBackend(t, front, backBar, msg)
}

Expand Down

0 comments on commit a64c39c

Please sign in to comment.