Skip to content

Commit

Permalink
Make the linter happy!
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustvo Chain committed Apr 26, 2018
1 parent 9ec7add commit 249f07d
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 65 deletions.
5 changes: 4 additions & 1 deletion cmd/httplab/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
flag "github.com/spf13/pflag"
)

// VERSION is the current version
const VERSION = "v0.5.0-dev"

// NewHandler returns a new http.Handler
func NewHandler(ui *ui.UI, g *gocui.Gui) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
if err := ui.AddRequest(g, req); err != nil {
Expand Down Expand Up @@ -54,6 +56,7 @@ func usage() {
fmt.Fprintf(os.Stderr, "\nBindings:\n%s", ui.Bindings.Help())
}

// Version prints the version and exits
func Version() {
fmt.Fprintf(os.Stdout, "%s\n", VERSION)
os.Exit(0)
Expand All @@ -78,7 +81,7 @@ func main() {
flag.Usage = usage

flag.BoolVarP(&args.autoUpdate, "auto-update", "a", true, "Auto-updates response when fields change.")
flag.StringVarP(&args.body, "body", "b", "Hello, World", "Specifies the inital response body.")
flag.StringVarP(&args.body, "body", "b", "Hello, World", "Specifies the initial response body.")
flag.StringVarP(&args.config, "config", "c", "", "Specifies custom config path.")
flag.BoolVar(&args.corsEnabled, "cors", false, "Enable CORS.")
flag.BoolVar(&args.corsDisplay, "cors-display", true, "Display CORS requests.")
Expand Down
2 changes: 2 additions & 0 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var decolorizeRegex = regexp.MustCompile("\x1b\\[0;\\d+m")

// Decolorize remove the color escape sequences from a []byte encoded string
func Decolorize(s []byte) []byte {
return decolorizeRegex.ReplaceAll(s, nil)
}
Expand Down Expand Up @@ -48,6 +49,7 @@ func writeBody(buf *bytes.Buffer, req *http.Request) error {
return err
}

// DumpRequest pretty prints an http.Request
func DumpRequest(req *http.Request) ([]byte, error) {
buf := bytes.NewBuffer(nil)

Expand Down
9 changes: 5 additions & 4 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"net/http"
"testing"

"sort"
"strings"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"strings"
"sort"
)

func TestDumpRequestWithJSON(t *testing.T) {
Expand Down Expand Up @@ -50,14 +51,14 @@ func TestDumpRequestHeaders(t *testing.T) {
sort.Strings(keys)

startLine := "GET / HTTP/1.1\n"
response := startLine + strings.Join(keys, ": \n") + ": \n"
response := startLine + strings.Join(keys, ": \n") + ": \n"

assert.Contains(t, response, string(Decolorize(buf)))
})
}

func TestDecolorization(t *testing.T) {
for i, _ := range [107]struct{}{} {
for i := range [107]struct{}{} {
text := "Some Text"
nocolor := Decolorize([]byte(withColor(i, text)))
assert.Equal(t, text, string(nocolor))
Expand Down
4 changes: 3 additions & 1 deletion response.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func (m BodyMode) String() string {
}

const (
// BodyInput takes the body input from input box
BodyInput BodyMode = iota + 1
// BodyFile takes the body input from a file
BodyFile
)

Expand Down Expand Up @@ -356,7 +358,7 @@ func (rl *ResponsesList) Del(key string) bool {
// ExpandPath expands a given path by replacing '~' with $HOME of the current user.
func ExpandPath(path string) string {
if path[0] == '~' {
path = "$HOME" + path[1:len(path)]
path = "$HOME" + path[1:]
}
return os.ExpandEnv(path)
}
Expand Down
2 changes: 2 additions & 0 deletions ui/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jroimartin/gocui"
)

// ActionFn is binded to a key combination
type ActionFn func(*gocui.Gui, *gocui.View) error

type binding struct {
Expand Down Expand Up @@ -59,6 +60,7 @@ func (bs bindings) Help() string {
return buf.String()
}

// Bindings are the list of binded key combinations
var Bindings = &bindings{
{gocui.KeyTab, "Tab", "Next Input", nil, onNextView},
{0xFF, "Shift+Tab", "Previous Input", nil, nil}, // only to display on help
Expand Down
8 changes: 7 additions & 1 deletion ui/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package ui

import "math"

// Split simplifies the layout definition.
type Split struct {
size int
left int
points []int
index int
}

// NewSplit returns a new Split
func NewSplit(size int) *Split {
return &Split{size: size, left: size, points: []int{0}}
}

// Fixed defines a set of fixed or absolute points
func (s *Split) Fixed(points ...int) *Split {
for _, point := range points {
s.points = append(s.points, point+(s.size-s.left))
Expand All @@ -22,6 +25,7 @@ func (s *Split) Fixed(points ...int) *Split {
return s
}

// Relative defines a set of relative points
func (s *Split) Relative(points ...int) *Split {
for _, point := range points {
per := float64(point) / 100.0
Expand All @@ -31,16 +35,18 @@ func (s *Split) Relative(points ...int) *Split {
return s
}

// Next returns the next point in the set
func (s *Split) Next() int {
if s.index+1 == len(s.points) {
return 0
}

s.index += 1
s.index = s.index + 1
next := s.points[s.index]
return next
}

// Current returns the current point in the set
func (s *Split) Current() int {
return s.points[s.index]
}
Loading

0 comments on commit 249f07d

Please sign in to comment.