1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-11-08 17:30:10 +00:00

Lint: Fix linter warnings / errors

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-06-27 19:50:43 +02:00
parent 853eb30b98
commit af53a31d2c
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 18 additions and 7 deletions

View file

@ -11,6 +11,11 @@ import (
pwd "github.com/Luzifer/password/v2/lib"
)
const (
defaultPasswordCount = 1
defaultPasswordLength = 20
)
func getCmdGet() *cobra.Command {
cmd := cobra.Command{
Use: "get",
@ -19,8 +24,8 @@ func getCmdGet() *cobra.Command {
}
cmd.Flags().BoolVarP(&flags.CLI.JSON, "json", "j", false, "return output in JSON format")
cmd.Flags().IntVarP(&flags.CLI.Length, "length", "l", 20, "length of the generated password")
cmd.Flags().IntVarP(&flags.CLI.Num, "number", "n", 1, "number of passwords to generate")
cmd.Flags().IntVarP(&flags.CLI.Length, "length", "l", defaultPasswordLength, "length of the generated password")
cmd.Flags().IntVarP(&flags.CLI.Num, "number", "n", defaultPasswordCount, "number of passwords to generate")
cmd.Flags().BoolVarP(&flags.CLI.SpecialCharacters, "special", "s", false, "use special characters in your password")
cmd.Flags().BoolVarP(&flags.CLI.XKCD, "xkcd", "x", false, "use XKCD style password")
@ -66,7 +71,7 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
case err == pwd.ErrLengthTooLow:
fmt.Println("The password has to be more than 4 characters long to meet the security considerations")
default:
fmt.Println("An unknown error occured")
fmt.Println("An unknown error occurred")
}
os.Exit(1)
}

View file

@ -9,12 +9,15 @@ import (
"strconv"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
http_helper "github.com/Luzifer/go_helpers/v2/http"
pwd "github.com/Luzifer/password/v2/lib"
)
const defaultHTTPListenPort = 3000
func getCmdServe() *cobra.Command {
cmd := cobra.Command{
Use: "serve",
@ -22,7 +25,7 @@ func getCmdServe() *cobra.Command {
Run: actionCmdServe,
}
cmd.Flags().IntVar(&flags.Server.Port, "port", 3000, "port to listen on")
cmd.Flags().IntVar(&flags.Server.Port, "port", defaultHTTPListenPort, "port to listen on")
return &cmd
}
@ -62,6 +65,11 @@ func handleAPIGetPasswordv1(res http.ResponseWriter, r *http.Request) {
password, err = pwd.NewSecurePassword().GeneratePassword(length, special)
}
if err != nil {
http.Error(res, errors.Wrap(err, "generating password").Error(), http.StatusInternalServerError)
return
}
res.Header().Add("Content-Type", "text/plain")
res.Header().Add("Cache-Control", "no-cache")
res.Write([]byte(password))

View file

@ -2,9 +2,7 @@ package main
import "github.com/spf13/cobra"
var (
version = "dev"
)
var version = "dev"
func main() {
rootCmd := cobra.Command{