Skip to content

Commit

Permalink
Merge pull request #3 from wikylyu/main
Browse files Browse the repository at this point in the history
feat: allow not to set logger
  • Loading branch information
firefart authored Jan 26, 2023
2 parents be1ab07 + e661729 commit c468788
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ type Logger interface {
Warn(args ...interface{})
Warnf(format string, args ...interface{})
}

type NilLogger struct {
}

func (l *NilLogger) Debug(args ...interface{}) {}
func (l *NilLogger) Debugf(format string, args ...interface{}) {}
func (l *NilLogger) Infof(format string, args ...interface{}) {}
func (l *NilLogger) Info(args ...interface{}) {}
func (l *NilLogger) Error(args ...interface{}) {}
func (l *NilLogger) Errorf(format string, args ...interface{}) {}
func (l *NilLogger) Warn(args ...interface{}) {}
func (l *NilLogger) Warnf(format string, args ...interface{}) {}
3 changes: 1 addition & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package socks

import (
"context"
"fmt"
"io"
"net"
"time"
Expand Down Expand Up @@ -30,7 +29,7 @@ type Proxy struct {
// Start is the main function to start a proxy
func (p *Proxy) Start() error {
if p.Log == nil {
return fmt.Errorf("please supply a logger")
p.Log = &NilLogger{} // allow not to set logger
}

listener, err := net.Listen("tcp", p.ServerAddr)
Expand Down

0 comments on commit c468788

Please sign in to comment.