Implement golint suggestions

This commit is contained in:
Marcin Kulik
2014-11-15 13:33:20 +01:00
parent 5ff2567755
commit 41d1d71ab6
7 changed files with 34 additions and 34 deletions

View File

@@ -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),

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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{

View File

@@ -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