lint: fix all major issues

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-14 16:16:01 +03:00
parent a11dd00174
commit 4ec4c277b7
65 changed files with 302 additions and 146 deletions

View File

@@ -17,6 +17,7 @@ type httpProfile struct {
}
var (
// DefaultAddress for http profiler
DefaultAddress = ":6060"
)
@@ -60,7 +61,8 @@ func (h *httpProfile) String() string {
return "http"
}
func NewProfile(opts ...profile.Option) profile.Profile {
// NewProfile returns new http profiler
func NewProfile(opts ...profile.Option) profile.Profiler {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)

20
profiler/noop.go Normal file
View File

@@ -0,0 +1,20 @@
package profiler
type noopProfiler struct{}
func (p *noopProfiler) Start() error {
return nil
}
func (p *noopProfiler) Stop() error {
return nil
}
func (p *noopProfiler) String() string {
return "noop"
}
// NewProfiler returns new noop profiler
func NewProfiler(opts ...Option) Profiler {
return &noopProfiler{}
}

View File

@@ -111,12 +111,11 @@ func (p *profiler) String() string {
return "pprof"
}
func NewProfile(opts ...profile.Option) profile.Profile {
var options profile.Options
// NewProfile create new profiler
func NewProfile(opts ...profile.Option) profile.Profiler {
options := profile.Options{}
for _, o := range opts {
o(&options)
}
p := new(profiler)
p.opts = options
return p
return &profiler{opts: options}
}

View File

@@ -1,7 +1,8 @@
// Package profile is for profilers
package profile
// Package profiler is for profilers
package profiler
type Profile interface {
// Profiler interface
type Profiler interface {
// Start the profiler
Start() error
// Stop the profiler
@@ -11,28 +12,17 @@ type Profile interface {
}
var (
DefaultProfile Profile = &NoopProfile{}
// DefaultProfiler holds the default profiler
DefaultProfiler Profiler = NewProfiler()
)
type NoopProfile struct{}
func (p *NoopProfile) Start() error {
return nil
}
func (p *NoopProfile) Stop() error {
return nil
}
func (p *NoopProfile) String() string {
return "noop"
}
// Options holds the options for profiler
type Options struct {
// Name to use for the profile
Name string
}
// Option func signature
type Option func(o *Options)
// Name of the profile