From 85d3e8ac43e2493b5de3cc195ee6ab3da6c67bae Mon Sep 17 00:00:00 2001
From: Ruben Pollan <meskio@sindominio.net>
Date: Sat, 26 Oct 2019 14:10:32 +0200
Subject: [PATCH] Add logger interface

And deprecate GetLastError
---
 shapeshifter.go | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/shapeshifter.go b/shapeshifter.go
index 5387a6d..f201e07 100644
--- a/shapeshifter.go
+++ b/shapeshifter.go
@@ -13,11 +13,16 @@ import (
 	"golang.org/x/net/proxy"
 )
 
+type Logger interface {
+	Log(msg string)
+}
+
 type ShapeShifter struct {
 	Cert      string
 	IatMode   int
 	Target    string // remote ip:port obfs4 server
 	SocksAddr string // -proxylistenaddr in shapeshifter-dispatcher
+	Logger    Logger
 	ln        net.Listener
 	errChan   chan error
 }
@@ -54,13 +59,6 @@ func (ss *ShapeShifter) GetErrorChannel() chan error {
 	return ss.errChan
 }
 
-func (ss *ShapeShifter) GetLastError() error {
-	if ss.errChan == nil {
-		ss.errChan = make(chan error, 2)
-	}
-	return <-ss.errChan
-}
-
 func (ss ShapeShifter) clientAcceptLoop() error {
 	for {
 		conn, err := ss.ln.Accept()
@@ -147,6 +145,11 @@ func (ss *ShapeShifter) checkOptions() error {
 }
 
 func (ss *ShapeShifter) sendError(format string, a ...interface{}) {
+	if ss.Logger != nil {
+		ss.Logger.Log(fmt.Sprintf(format, a...))
+		return
+	}
+
 	if ss.errChan == nil {
 		ss.errChan = make(chan error, 2)
 	}
-- 
GitLab