Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xenohe committed Jun 22, 2023
1 parent a9dfb6f commit e4cfb84
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
14 changes: 7 additions & 7 deletions formats/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

var iec_units = [...]string{
var iecUnits = [...]string{
"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB",
}

Expand All @@ -16,20 +16,20 @@ func isFinite(f float64) bool {

func IECBytes(value float64) string {
if !isFinite(value) || value < 8192.0 {
return fmt.Sprintf("%.0f %s", value, iec_units[0])
return fmt.Sprintf("%.0f %s", value, iecUnits[0])
}
n := (int(math.Log2(value)) - 3) / 10
if n >= len(iec_units) {
n = len(iec_units) - 1
if n >= len(iecUnits) {
n = len(iecUnits) - 1
}
v := math.Ldexp(value, n*-10)
if v < 10.0 {
return fmt.Sprintf("%.02f %s", v, iec_units[n])
return fmt.Sprintf("%.02f %s", v, iecUnits[n])
}
if v < 100.0 {
return fmt.Sprintf("%.01f %s", v, iec_units[n])
return fmt.Sprintf("%.01f %s", v, iecUnits[n])
}
return fmt.Sprintf("%.0f %s", v, iec_units[n])
return fmt.Sprintf("%.0f %s", v, iecUnits[n])
}

func DurationSeconds(d time.Duration) string {
Expand Down
9 changes: 8 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (h *TLSHandler) Serve(ctx context.Context, conn net.Conn) {
atomic.AddUint32(&h.unauthorized, 1)
defer atomic.AddUint32(&h.unauthorized, ^uint32(0))
start := time.Now()
if deadline, ok := ctx.Deadline(); ok {
if err := conn.SetDeadline(deadline); err != nil {
slog.Errorf("tunnel %q: accept %v, (%T) %v", h.t.name, conn.RemoteAddr(), err, err)
return
}
}
c := h.s.getConfig()
c.SetConnParams(conn)
conn = meter.Conn(conn, h.s.meter)
Expand All @@ -54,6 +60,7 @@ func (h *TLSHandler) Serve(ctx context.Context, conn net.Conn) {
slog.Errorf("tunnel %q: accept %v, (%T) %v", h.t.name, conn.RemoteAddr(), err, err)
return
}
_ = conn.SetDeadline(time.Time{})
tun := h.t
if handshake.Identity != "" {
if t := h.s.findTunnel(handshake.Identity); t != nil {
Expand Down Expand Up @@ -117,6 +124,6 @@ func (h *TunnelHandler) Serve(ctx context.Context, accepted net.Conn) {
// EmptyHandler rejects all connections
type EmptyHandler struct{}

func (h *EmptyHandler) Serve(ctx context.Context, accepted net.Conn) {
func (h *EmptyHandler) Serve(_ context.Context, accepted net.Conn) {
_ = accepted.Close()
}
2 changes: 1 addition & 1 deletion metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RunHTTPServer(l net.Listener, s *Server) error {
b, err := json.MarshalIndent(s.getConfig(), "", " ")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
return
}
w.Header().Set("Cache-Control", "no-cache")
Expand Down
8 changes: 5 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
const network = "tcp"

var (
ErrShutdown = errors.New("server is shutting down")
ErrNoSession = errors.New("no session available")
)

Expand Down Expand Up @@ -162,7 +161,10 @@ func (s *Server) Start() error {
return err
}
if err := s.g.Go(func() {
RunHTTPServer(l, s)
err := RunHTTPServer(l, s)
if err != nil {
slog.Errorf("(%T) %v", err, err)
}
}); err != nil {
return err
}
Expand Down Expand Up @@ -208,7 +210,7 @@ func (s *Server) Shutdown() error {
return nil
}

// Load or reload configuration
// LoadConfig reloads the configuration file
func (s *Server) LoadConfig(cfg *Config) error {
s.cfgMu.Lock()
defer s.cfgMu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion slog/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func (l *lineOutput) Write(m logMessage) {
buf = append(buf, '\n')
}
l.buf = buf
l.out.Write(buf)
_, _ = l.out.Write(buf)
}
2 changes: 1 addition & 1 deletion tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestTLS(t *testing.T) {
b := make([]byte, 256)
n, _ := conn.Read(b)
println("tls: echo")
conn.Write(b[:n])
_, _ = conn.Write(b[:n])
_ = conn.Close()
}()
println("tls: dial")
Expand Down
6 changes: 6 additions & 0 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func (t *Tunnel) dial(ctx context.Context) (*yamux.Session, error) {
if err != nil {
return nil, err
}
if deadline, ok := ctx.Deadline(); ok {
if err := conn.SetDeadline(deadline); err != nil {
return nil, err
}
}
c := t.s.getConfig()
c.SetConnParams(conn)
conn = meter.Conn(conn, t.s.meter)
Expand All @@ -215,6 +220,7 @@ func (t *Tunnel) dial(ctx context.Context) (*yamux.Session, error) {
if err != nil {
return nil, err
}
_ = conn.SetDeadline(time.Time{})
tun := t
if handshake.Identity != "" {
if found := t.s.findTunnel(handshake.Identity); found != nil {
Expand Down

0 comments on commit e4cfb84

Please sign in to comment.