From 41d1d71ab6809ef19a8f39dcd4079103a9390a8d Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sat, 15 Nov 2014 13:33:20 +0100 Subject: [PATCH] Implement golint suggestions --- api/api.go | 24 ++++++++++++------------ api/http.go | 4 ++-- commands/auth.go | 8 ++++---- commands/rec.go | 8 ++++---- commands/rec_test.go | 8 ++++---- main.go | 2 +- util/cfg.go | 14 +++++++------- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/api/api.go b/api/api.go index 79a2af1..03f431d 100644 --- a/api/api.go +++ b/api/api.go @@ -17,29 +17,29 @@ type Frame struct { Data []byte } -type Api interface { +type API interface { CreateAsciicast([]Frame, time.Duration, int, int, string, string) (string, error) } -type AsciinemaApi struct { +type AsciinemaAPI struct { url string token string version string http HTTP } -func New(url, token, version string) *AsciinemaApi { - return &AsciinemaApi{ +func New(url, token, version string) *AsciinemaAPI { + return &AsciinemaAPI{ url: url, token: token, version: version, - http: &HttpClient{}, + http: &HTTPClient{}, } } -func (a *AsciinemaApi) CreateAsciicast(frames []Frame, duration time.Duration, cols, rows int, command, title string) (string, error) { +func (a *AsciinemaAPI) CreateAsciicast(frames []Frame, duration time.Duration, cols, rows int, command, title string) (string, error) { response, err := a.http.PostForm( - a.createUrl(), + a.createURL(), a.username(), a.token, a.createHeaders(), @@ -47,7 +47,7 @@ func (a *AsciinemaApi) CreateAsciicast(frames []Frame, duration time.Duration, c ) if err != nil { - return "", errors.New(fmt.Sprintf("Connection failed (%v)", err.Error())) + return "", fmt.Errorf("Connection failed (%v)", err.Error()) } defer response.Body.Close() @@ -71,21 +71,21 @@ func (a *AsciinemaApi) CreateAsciicast(frames []Frame, duration time.Duration, c return body.String(), nil } -func (a *AsciinemaApi) createUrl() string { +func (a *AsciinemaAPI) createURL() string { return a.url + "/api/asciicasts" } -func (a *AsciinemaApi) username() string { +func (a *AsciinemaAPI) username() string { return os.Getenv("USER") } -func (a *AsciinemaApi) createHeaders() map[string]string { +func (a *AsciinemaAPI) createHeaders() map[string]string { return map[string]string{ "User-Agent": fmt.Sprintf("asciinema/%s %s/%s %s-%s", a.version, runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH), } } -func (a *AsciinemaApi) createFiles(frames []Frame, duration time.Duration, cols, rows int, command, title string) map[string]io.Reader { +func (a *AsciinemaAPI) createFiles(frames []Frame, duration time.Duration, cols, rows int, command, title string) map[string]io.Reader { return map[string]io.Reader{ "asciicast[stdout]:stdout": gzippedDataReader(frames), "asciicast[stdout_timing]:stdout.time": gzippedTimingReader(frames), diff --git a/api/http.go b/api/http.go index 909e676..1031ad5 100644 --- a/api/http.go +++ b/api/http.go @@ -12,9 +12,9 @@ type HTTP interface { PostForm(string, string, string, map[string]string, map[string]io.Reader) (*http.Response, error) } -type HttpClient struct{} +type HTTPClient struct{} -func (c *HttpClient) PostForm(url, username, password string, headers map[string]string, files map[string]io.Reader) (*http.Response, error) { +func (c *HTTPClient) PostForm(url, username, password string, headers map[string]string, files map[string]io.Reader) (*http.Response, error) { req, err := createPostRequest(url, username, password, headers, files) if err != nil { return nil, err diff --git a/commands/auth.go b/commands/auth.go index 592909e..e8aad95 100644 --- a/commands/auth.go +++ b/commands/auth.go @@ -9,14 +9,14 @@ import ( ) type AuthCommand struct { - apiUrl string + apiURL string apiToken string } func NewAuthCommand(cfg *util.Config) cli.Command { return &AuthCommand{ - apiUrl: cfg.Api.Url, - apiToken: cfg.Api.Token, + apiURL: cfg.API.URL, + apiToken: cfg.API.Token, } } @@ -25,7 +25,7 @@ func (c *AuthCommand) RegisterFlags(flags *flag.FlagSet) { func (c *AuthCommand) Execute(args []string) error { fmt.Println("Open the following URL in your browser to register your API token and assign any recorded asciicasts to your profile:") - fmt.Printf("%v/connect/%v\n", c.apiUrl, c.apiToken) + fmt.Printf("%v/connect/%v\n", c.apiURL, c.apiToken) return nil } diff --git a/commands/rec.go b/commands/rec.go index de95b46..92c64d7 100644 --- a/commands/rec.go +++ b/commands/rec.go @@ -14,16 +14,16 @@ import ( type RecordCommand struct { Cfg *util.Config - Api api.Api + API api.API Terminal terminal.Terminal Command string Title string NoConfirm bool } -func NewRecordCommand(api api.Api, cfg *util.Config) cli.Command { +func NewRecordCommand(api api.API, cfg *util.Config) cli.Command { return &RecordCommand{ - Api: api, + API: api, Cfg: cfg, Terminal: terminal.New(), } @@ -82,7 +82,7 @@ func (c *RecordCommand) Execute(args []string) error { rows, cols, _ = c.Terminal.Size() - url, err := c.Api.CreateAsciicast(stdout.Frames, stdout.Duration(), cols, rows, c.Command, c.Title) + url, err := c.API.CreateAsciicast(stdout.Frames, stdout.Duration(), cols, rows, c.Command, c.Title) if err != nil { return err } diff --git a/commands/rec_test.go b/commands/rec_test.go index 8ee32b0..66b71c7 100644 --- a/commands/rec_test.go +++ b/commands/rec_test.go @@ -29,12 +29,12 @@ func (t *testTerminal) Record(command string, stdoutCopy io.Writer) error { return nil } -type testApi struct { +type testAPI struct { err error t *testing.T } -func (a *testApi) CreateAsciicast(frames []api.Frame, duration time.Duration, cols, rows int, command, title string) (string, error) { +func (a *testAPI) CreateAsciicast(frames []api.Frame, duration time.Duration, cols, rows int, command, title string) (string, error) { if command != "ls" { a.t.Errorf("expected command to be set on asciicast") } @@ -84,13 +84,13 @@ func TestRecordCommand_Execute(t *testing.T) { for _, test := range tests { terminal := &testTerminal{err: test.recordError} - api := &testApi{err: test.apiError, t: t} + api := &testAPI{err: test.apiError, t: t} command := &commands.RecordCommand{ Command: "ls", Title: "listing", Terminal: terminal, - Api: api, + API: api, } err := command.Execute(nil) diff --git a/main.go b/main.go index f98e901..de383a6 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { os.Exit(1) } - api := api.New(cfg.Api.Url, cfg.Api.Token, Version) + api := api.New(cfg.API.URL, cfg.API.Token, Version) cli := &cli.CLI{ Commands: map[string]cli.Command{ diff --git a/util/cfg.go b/util/cfg.go index e95208f..b3be5f7 100644 --- a/util/cfg.go +++ b/util/cfg.go @@ -12,13 +12,13 @@ import ( ) const ( - DEFAULT_API_URL = "https://asciinema.org" + DefaultAPIURL = "https://asciinema.org" ) type Config struct { - Api struct { + API struct { Token string - Url string + URL string } Record struct { Command string @@ -38,12 +38,12 @@ func LoadConfig() (*Config, error) { return nil, err } - if cfg.Api.Url == "" { - cfg.Api.Url = DEFAULT_API_URL + if cfg.API.URL == "" { + cfg.API.URL = DefaultAPIURL } - if envApiUrl := os.Getenv("ASCIINEMA_API_URL"); envApiUrl != "" { - cfg.Api.Url = envApiUrl + if envAPIURL := os.Getenv("ASCIINEMA_API_URL"); envAPIURL != "" { + cfg.API.URL = envAPIURL } return cfg, nil