diff --git a/Makefile b/Makefile index f369e2a..8b4ecce 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,16 @@ +EXECPATH = ./build/dist + lint: golangci-lint run dev: air -run: - go run main.go +build: + go build -o $(EXECPATH) . + +run: build + $(EXECPATH) new run-web: go run main.go --web=t @@ -16,4 +21,4 @@ web: test: go test -json -count=1 ./... -coverpkg=./... -coverprofile coverage.txt -covermode=atomic | gotestfmt && go tool cover -html coverage.txt && rm coverage.txt -.PHONY: lint run dev run-web test \ No newline at end of file +.PHONY: lint run dev run-web test build diff --git a/api/handlers.go b/api/handlers.go index 8700743..fe381a9 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -15,7 +15,7 @@ func (s Server) HandleNewPassword(w http.ResponseWriter, r *http.Request) { log.Fatal(err) } opts := passgen.Options{Length: params.Length, WithNumbers: params.WithNumbers} - password := passgen.NewPasswordGenerator(opts.SetDefaults()).NewPassword() + password := passgen.New(opts.SetDefaults()).NewPassword() render.Status(r, http.StatusAccepted) err := render.Render(w, r, &PasswordResponse{Password: password}) diff --git a/cmd/new.go b/cmd/new.go index 8c7980a..dd38872 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -21,7 +21,7 @@ var newPasswordCommand = &cobra.Command{Use: "new", Long: "Create a secure password", Run: func(cmd *cobra.Command, args []string) { opts := passgen.Options{Length: Length, WithNumbers: WithNumbers} - pg := passgen.NewPasswordGenerator(opts.SetDefaults()) + pg := passgen.New(opts.SetDefaults()) password := pg.NewPassword() display(password) }} diff --git a/passgen/passgen.go b/passgen/passgen.go index ef1b354..e795530 100644 --- a/passgen/passgen.go +++ b/passgen/passgen.go @@ -11,8 +11,8 @@ type PasswordGenerator struct { options *Options } -// NewPasswordGenerator returns a valid PasswordGenerator given the specified Options. -func NewPasswordGenerator(opts *Options) *PasswordGenerator { +// New returns a valid PasswordGenerator given the specified Options. +func New(opts *Options) *PasswordGenerator { pg := &PasswordGenerator{} pg.options = opts.SetDefaults() pg.characters = pg.shuffleCharacters(opts.WithNumbers) diff --git a/passgen/passgen_test.go b/passgen/passgen_test.go index 12cda6e..a25bc6e 100644 --- a/passgen/passgen_test.go +++ b/passgen/passgen_test.go @@ -12,7 +12,7 @@ func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) { opts := &passgen.Options{ Length: rand.Intn(12), // nolint } - pg := passgen.NewPasswordGenerator(opts) + pg := passgen.New(opts) if password := pg.NewPassword(); len(password) != opts.Length { t.Errorf("Expected a password to be %d characters long, got %d", opts.Length, len(password)) @@ -20,7 +20,7 @@ func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) { } func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) { - pg := passgen.NewPasswordGenerator(&passgen.Options{}) + pg := passgen.New(&passgen.Options{}) if password := pg.NewPassword(); len(password) != 6 { t.Errorf("Expected a password to be %d characters long, got %d", 6, len(password)) @@ -31,7 +31,7 @@ func TestGeneratePasswordWithLettersAndNumbers(t *testing.T) { opts := &passgen.Options{ WithNumbers: true, } - pg := passgen.NewPasswordGenerator(opts) + pg := passgen.New(opts) if password := pg.NewPassword(); !containNumbers(password) { t.Errorf("Expected password to contain NUMBERS, got %q", password)