Skip to content

Commit 228d8eb

Browse files
committed
all: remove logrus from dependency
1 parent cb33e2e commit 228d8eb

39 files changed

+51
-3010
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ gossa
1414

1515
# Dependency directories (remove the comment below to include it)
1616
# vendor/
17-
data/
17+
data/
18+
public/buildbox/

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.14
55
require (
66
github.com/gin-gonic/gin v1.6.2
77
github.com/google/uuid v1.1.1
8-
github.com/sirupsen/logrus v1.5.0
98
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e
109
gopkg.in/yaml.v2 v2.2.8
1110
)

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
2020
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2121
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
2222
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
23-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
24-
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
2523
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
2624
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
2725
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
@@ -32,18 +30,14 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
3230
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
3331
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3432
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
35-
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
36-
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
3733
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
38-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
3934
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4035
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
4136
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
4237
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
4338
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
4439
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
4540
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
46-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4741
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
4842
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4943
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

src/boot/boot.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ package boot
66

77
import (
88
"context"
9+
"log"
910
"net/http"
1011
"os"
1112
"os/signal"
13+
"syscall"
1214
"time"
1315

14-
"github.com/sirupsen/logrus"
1516
"golang.design/x/ssaplayground/src/config"
1617
"golang.design/x/ssaplayground/src/route"
1718
)
1819

1920
func init() {
21+
log.SetPrefix("redir: ")
22+
log.SetFlags(log.Lmsgprefix | log.LstdFlags | log.Lshortfile)
2023
config.Init()
2124
}
2225

@@ -30,27 +33,27 @@ func Run() {
3033

3134
go func() {
3235
quit := make(chan os.Signal, 1)
33-
signal.Notify(quit, os.Interrupt, os.Kill)
36+
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
3437
sig := <-quit
3538

36-
logrus.Info("ssaplayground: service is stopped with signal: ", sig)
39+
log.Printf("service is stopped with signal: %v", sig)
3740

3841
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
3942
if err := server.Shutdown(ctx); err != nil {
40-
logrus.Errorf("ssaplayground: close ssaplayground with error: %v", err)
43+
log.Printf("close ssaplayground with error: %v", err)
4144
}
4245

4346
cancel()
4447
terminated <- true
4548
}()
4649

47-
logrus.Infof("ssaplayground: welcome to ssaplayground service... http://%s/gossa", config.Get().Addr)
50+
log.Printf("welcome to ssaplayground service... http://%s/gossa", config.Get().Addr)
4851
err := server.ListenAndServe()
4952
if err != http.ErrServerClosed {
5053
terminated <- true
51-
logrus.Info("ssaplayground: launch with error: ", err)
54+
log.Printf("launch with error: %v", err)
5255
}
5356

5457
<-terminated
55-
logrus.Info("ssaplayground: service has terminated successfully, good bye!")
58+
log.Printf("service has terminated successfully, good bye!")
5659
}

src/config/config.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"flag"
99
"fmt"
1010
"io/ioutil"
11+
"log"
1112
"os"
1213

1314
"github.com/gin-gonic/gin"
14-
"github.com/sirupsen/logrus"
1515
"gopkg.in/yaml.v2"
1616
)
1717

@@ -49,17 +49,15 @@ Usage:
4949

5050
y, err := ioutil.ReadFile(f)
5151
if err != nil {
52-
logrus.Fatalf("fatal: fail to read configuration file: %v", err)
52+
log.Fatalf("fatal: fail to read configuration file: %v", err)
5353
}
5454

5555
conf = &Config{}
5656
err = yaml.Unmarshal(y, conf)
5757
if err != nil {
58-
logrus.Fatalf("fatal: fail to parse configuration file: %v", err)
58+
log.Fatalf("fatal: fail to parse configuration file: %v", err)
5959
}
6060
gin.SetMode(conf.Mode)
6161

62-
logrus.SetFormatter(&logrus.TextFormatter{})
63-
logrus.SetReportCaller(false)
64-
logrus.Infof("load config file: %q", f)
62+
log.Printf("load config file: %q", f)
6563
}

src/route/router.go

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@
55
package route
66

77
import (
8+
"fmt"
9+
"log"
810
"net/http"
911
"net/http/pprof"
12+
"strings"
1013

1114
"github.com/gin-gonic/gin"
12-
"github.com/sirupsen/logrus"
1315
"golang.design/x/ssaplayground/src/config"
1416
)
1517

16-
// Register routers
18+
// Register routers for the ssa service.
1719
func Register() *gin.Engine {
18-
r := &Router{
19-
Engine: gin.Default(),
20-
}
20+
r := &Router{Engine: gin.Default()}
2121
r.SetupAPI()
2222
r.SetupApp()
23-
if config.Get().Mode != "debug" {
23+
if config.Get().Mode != gin.DebugMode {
2424
return r.Engine
2525
}
2626
r.SetupProfile()
2727
return r.Engine
2828
}
2929

30-
// Router ...
30+
// Router is a router engine.
3131
type Router struct {
3232
Engine *gin.Engine
3333
}
3434

35-
// SetupAPI ...
35+
// SetupAPI serves the API endpoints of the gossa service.
3636
func (r *Router) SetupAPI() {
3737
v1 := r.Engine.Group("/gossa/api/v1")
3838
{
@@ -41,46 +41,54 @@ func (r *Router) SetupAPI() {
4141
}
4242
}
4343

44-
// SetupApp ...
44+
// SetupApp serves the static website of Go SSA Playground.
4545
func (r *Router) SetupApp() {
4646
r.Engine.Use(static("/gossa"))
47-
logrus.Infof("GoSSAWeb is on: http://%s, static: %s", config.Get().Addr, config.Get().Static)
47+
log.Printf("GoSSAWeb is on: http://%s, static: %s", config.Get().Addr, config.Get().Static)
4848
}
4949

50-
// SetupProfile profiles the standard HandlerFuncs from the net/http/pprof package with
50+
// SetupProfile the standard HandlerFuncs from the net/http/pprof package with
5151
// the provided gin.Engine. prefixOptions is a optional. If not prefixOptions,
5252
// the default path prefix is used, otherwise first prefixOptions will be path prefix.
5353
//
5454
// Basic Usage:
5555
//
5656
// - use the pprof tool to look at the heap profile:
57-
// go tool pprof http://localhost:9999/debug/pprof/heap
57+
// go tool pprof localhost:8080/midgard/api/v1/debug/pprof/heap
5858
// - look at a 30-second CPU profile:
59-
// go tool pprof http://localhost:9999/debug/pprof/profile
59+
// go tool pprof localhost:8080/midgard/api/v1/debug/pprof/profile
6060
// - look at the goroutine blocking profile, after calling runtime.SetBlockProfileRate:
61-
// go tool pprof http://localhost:9999/debug/pprof/block
61+
// go tool pprof localhost:8080/midgard/api/v1/debug/pprof/block
6262
// - collect a 5-second execution trace:
63-
// wget http://localhost:9999/debug/pprof/trace?seconds=5
63+
// go tool pprof localhost:8080/midgard/api/v1/debug/pprof/trace?seconds=5
6464
//
6565
func (r *Router) SetupProfile() {
6666
pprofHandler := func(h http.HandlerFunc) gin.HandlerFunc {
6767
handler := http.HandlerFunc(h)
6868
return func(c *gin.Context) {
69+
70+
fmt.Println(c.Request.Host)
71+
if !strings.Contains(c.Request.Host, "localhost") {
72+
c.AbortWithStatus(http.StatusUnauthorized)
73+
return
74+
}
75+
6976
handler.ServeHTTP(c.Writer, c.Request)
7077
}
7178
}
72-
prefixRouter := r.Engine.Group("/debug/pprof")
79+
rr := r.Engine.Group("/debug/pprof")
7380
{
74-
prefixRouter.GET("/", pprofHandler(pprof.Index))
75-
prefixRouter.GET("/cmdline", pprofHandler(pprof.Cmdline))
76-
prefixRouter.GET("/profile", pprofHandler(pprof.Profile))
77-
prefixRouter.POST("/symbol", pprofHandler(pprof.Symbol))
78-
prefixRouter.GET("/symbol", pprofHandler(pprof.Symbol))
79-
prefixRouter.GET("/trace", pprofHandler(pprof.Trace))
80-
prefixRouter.GET("/block", pprofHandler(pprof.Handler("block").ServeHTTP))
81-
prefixRouter.GET("/goroutine", pprofHandler(pprof.Handler("goroutine").ServeHTTP))
82-
prefixRouter.GET("/heap", pprofHandler(pprof.Handler("heap").ServeHTTP))
83-
prefixRouter.GET("/mutex", pprofHandler(pprof.Handler("mutex").ServeHTTP))
84-
prefixRouter.GET("/threadcreate", pprofHandler(pprof.Handler("threadcreate").ServeHTTP))
81+
rr.GET("/", pprofHandler(pprof.Index))
82+
rr.GET("/cmdline", pprofHandler(pprof.Cmdline))
83+
rr.GET("/profile", pprofHandler(pprof.Profile))
84+
rr.POST("/symbol", pprofHandler(pprof.Symbol))
85+
rr.GET("/symbol", pprofHandler(pprof.Symbol))
86+
rr.GET("/trace", pprofHandler(pprof.Trace))
87+
rr.GET("/allocs", pprofHandler(pprof.Handler("allocs").ServeHTTP))
88+
rr.GET("/block", pprofHandler(pprof.Handler("block").ServeHTTP))
89+
rr.GET("/goroutine", pprofHandler(pprof.Handler("goroutine").ServeHTTP))
90+
rr.GET("/heap", pprofHandler(pprof.Handler("heap").ServeHTTP))
91+
rr.GET("/mutex", pprofHandler(pprof.Handler("mutex").ServeHTTP))
92+
rr.GET("/threadcreate", pprofHandler(pprof.Handler("threadcreate").ServeHTTP))
8593
}
8694
}

vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE

Lines changed: 0 additions & 9 deletions
This file was deleted.

vendor/github.com/konsorten/go-windows-terminal-sequences/README.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

vendor/github.com/konsorten/go-windows-terminal-sequences/go.mod

Lines changed: 0 additions & 1 deletion
This file was deleted.

vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)