diff --git a/client/auth.go b/client/auth.go index 453e1cfe..fe49b3c7 100644 --- a/client/auth.go +++ b/client/auth.go @@ -4,7 +4,7 @@ import ( "encoding/json" charm "github.com/charmbracelet/charm/proto" - "github.com/golang-jwt/jwt/v4" + jwt "github.com/golang-jwt/jwt/v4" ) // Auth will authenticate a client and cache the result. It will return a diff --git a/client/client.go b/client/client.go index 193d2640..f14c846a 100644 --- a/client/client.go +++ b/client/client.go @@ -13,11 +13,11 @@ import ( "strings" "sync" - "github.com/caarlos0/env/v6" + env "github.com/caarlos0/env/v6" charm "github.com/charmbracelet/charm/proto" "github.com/charmbracelet/keygen" - "github.com/golang-jwt/jwt/v4" - "github.com/mitchellh/go-homedir" + jwt "github.com/golang-jwt/jwt/v4" + homedir "github.com/mitchellh/go-homedir" gap "github.com/muesli/go-app-paths" "golang.org/x/crypto/ssh" ) diff --git a/client/http.go b/client/http.go index 44709adb..dc7fe972 100644 --- a/client/http.go +++ b/client/http.go @@ -30,7 +30,7 @@ func (cc *Client) AuthedJSONRequest(method string, path string, reqBody interfac return err } headers := http.Header{ - "Content-Type": {"application/json"}, + "Content-Type": []string{"application/json"}, } resp, err := cc.AuthedRequest(method, path, headers, buf) if err != nil { diff --git a/cmd/completion.go b/cmd/completion.go index a8e31a83..9d0f48f0 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -51,7 +51,7 @@ var CompletionCmd = &cobra.Command{ Long: completionInstructions(), DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { switch args[0] { case "bash": diff --git a/cmd/crypt.go b/cmd/crypt.go index 3aa8f977..ba27135b 100644 --- a/cmd/crypt.go +++ b/cmd/crypt.go @@ -62,7 +62,7 @@ type cryptFile struct { Data string `json:"data"` } -func cryptEncrypt(cmd *cobra.Command, args []string) error { +func cryptEncrypt(_ *cobra.Command, _ []string) error { cr, err := crypt.NewCrypt() if err != nil { return err @@ -88,7 +88,7 @@ func cryptEncrypt(cmd *cobra.Command, args []string) error { return nil } -func cryptDecrypt(cmd *cobra.Command, args []string) error { +func cryptDecrypt(_ *cobra.Command, args []string) error { var r io.Reader cr, err := crypt.NewCrypt() if err != nil { @@ -127,7 +127,7 @@ func cryptDecrypt(cmd *cobra.Command, args []string) error { return nil } -func cryptEncryptLookup(cmd *cobra.Command, args []string) error { +func cryptEncryptLookup(_ *cobra.Command, args []string) error { cr, err := crypt.NewCrypt() if err != nil { return err @@ -140,7 +140,7 @@ func cryptEncryptLookup(cmd *cobra.Command, args []string) error { return nil } -func cryptDecryptLookup(cmd *cobra.Command, args []string) error { +func cryptDecryptLookup(_ *cobra.Command, args []string) error { cr, err := crypt.NewCrypt() if err != nil { return err diff --git a/cmd/fs.go b/cmd/fs.go index 88fee7d9..07dd6509 100644 --- a/cmd/fs.go +++ b/cmd/fs.go @@ -222,7 +222,7 @@ func (lrfs *localRemoteFS) copy(srcName string, dstName string, recursive bool) return lrfs.write(dstName, src) } -func fsCat(cmd *cobra.Command, args []string) error { +func fsCat(_ *cobra.Command, args []string) error { lsfs, err := cfs.NewFS() if err != nil { return err @@ -254,7 +254,7 @@ func fsMove(cmd *cobra.Command, args []string) error { return fsRemove(cmd, args[:1]) } -func fsRemove(cmd *cobra.Command, args []string) error { +func fsRemove(_ *cobra.Command, args []string) error { lsfs, err := cfs.NewFS() if err != nil { return err @@ -262,7 +262,7 @@ func fsRemove(cmd *cobra.Command, args []string) error { return lsfs.Remove(args[0]) } -func fsCopy(cmd *cobra.Command, args []string) error { +func fsCopy(_ *cobra.Command, args []string) error { lrfs, err := newLocalRemoteFS() if err != nil { return err @@ -287,7 +287,7 @@ func fsCopy(cmd *cobra.Command, args []string) error { return lrfs.copy(src, dst, isRecursive) } -func fsList(cmd *cobra.Command, args []string) error { +func fsList(_ *cobra.Command, args []string) error { lsfs, err := cfs.NewFS() if err != nil { return err @@ -312,7 +312,7 @@ func fsList(cmd *cobra.Command, args []string) error { return nil } -func fsTree(cmd *cobra.Command, args []string) error { +func fsTree(_ *cobra.Command, args []string) error { lsfs, err := cfs.NewFS() if err != nil { return err diff --git a/cmd/import_keys.go b/cmd/import_keys.go index b69f71a3..0e48e350 100644 --- a/cmd/import_keys.go +++ b/cmd/import_keys.go @@ -217,15 +217,12 @@ func restoreFromReader(r io.Reader, dd string) error { return err } - if err := os.WriteFile( + err = os.WriteFile( keypath+".pub", ssh.MarshalAuthorizedKey(signer.PublicKey()), 0o600, - ); err != nil { - return err - } - - return nil + ) + return err } func untar(tarball, targetDir string) error { diff --git a/cmd/kv.go b/cmd/kv.go index 81ab4b8b..ed325072 100644 --- a/cmd/kv.go +++ b/cmd/kv.go @@ -8,7 +8,7 @@ import ( "github.com/charmbracelet/charm/kv" "github.com/charmbracelet/charm/ui/common" - "github.com/dgraph-io/badger/v3" + badger "github.com/dgraph-io/badger/v3" "github.com/spf13/cobra" ) @@ -80,7 +80,7 @@ var ( } ) -func kvSet(cmd *cobra.Command, args []string) error { +func kvSet(_ *cobra.Command, args []string) error { k, n, err := keyParser(args[0]) if err != nil { return err @@ -95,7 +95,7 @@ func kvSet(cmd *cobra.Command, args []string) error { return db.SetReader(k, os.Stdin) } -func kvGet(cmd *cobra.Command, args []string) error { +func kvGet(_ *cobra.Command, args []string) error { k, n, err := keyParser(args[0]) if err != nil { return err @@ -112,7 +112,7 @@ func kvGet(cmd *cobra.Command, args []string) error { return nil } -func kvDelete(cmd *cobra.Command, args []string) error { +func kvDelete(_ *cobra.Command, args []string) error { k, n, err := keyParser(args[0]) if err != nil { return err @@ -124,7 +124,7 @@ func kvDelete(cmd *cobra.Command, args []string) error { return db.Delete(k) } -func kvList(cmd *cobra.Command, args []string) error { +func kvList(_ *cobra.Command, args []string) error { var k string var pf string if keysIterate || valuesIterate { @@ -178,7 +178,7 @@ func kvList(cmd *cobra.Command, args []string) error { }) } -func kvSync(cmd *cobra.Command, args []string) error { +func kvSync(_ *cobra.Command, args []string) error { n, err := nameFromArgs(args) if err != nil { return err @@ -190,7 +190,7 @@ func kvSync(cmd *cobra.Command, args []string) error { return db.Sync() } -func kvReset(cmd *cobra.Command, args []string) error { +func kvReset(_ *cobra.Command, args []string) error { n, err := nameFromArgs(args) if err != nil { return err diff --git a/fs/fs.go b/fs/fs.go index 14e1e9f9..9fb5583a 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -260,8 +260,8 @@ func (cfs *FS) WriteFile(name string, src fs.File) error { } path := fmt.Sprintf("/v1/fs/%s?mode=%d", ep, info.Mode()) headers := http.Header{ - "Content-Type": {w.FormDataContentType()}, - "Content-Length": {fmt.Sprintf("%d", contentLength)}, + "Content-Type": []string{w.FormDataContentType()}, + "Content-Length": []string{fmt.Sprintf("%d", contentLength)}, } resp, err := cfs.cc.AuthedRequest("POST", path, headers, rr) if err != nil { diff --git a/server/http.go b/server/http.go index ca3ff5d2..e308737f 100644 --- a/server/http.go +++ b/server/http.go @@ -169,14 +169,14 @@ func (s *HTTPServer) renderCustomError(w http.ResponseWriter, msg string, status _ = json.NewEncoder(w).Encode(charm.Message{Message: msg}) } -func (s *HTTPServer) handleJWKS(w http.ResponseWriter, r *http.Request) { +func (s *HTTPServer) handleJWKS(w http.ResponseWriter, _ *http.Request) { jwks := jose.JSONWebKeySet{Keys: []jose.JSONWebKey{s.cfg.jwtKeyPair.JWK.Public()}} w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Origin", "*") _ = json.NewEncoder(w).Encode(jwks) } -func (s *HTTPServer) handleOpenIDConfig(w http.ResponseWriter, r *http.Request) { +func (s *HTTPServer) handleOpenIDConfig(w http.ResponseWriter, _ *http.Request) { pj := providerJSON{JWKSURL: fmt.Sprintf("%s/v1/public/jwks", s.cfg.httpURL())} w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Origin", "*") diff --git a/server/jwk.go b/server/jwk.go index 19342417..714d01bb 100644 --- a/server/jwk.go +++ b/server/jwk.go @@ -5,7 +5,7 @@ import ( "crypto/sha256" "fmt" - "gopkg.in/square/go-jose.v2" + jose "gopkg.in/square/go-jose.v2" ) // JSONWebKeyPair holds the ED25519 private key and JSON Web Key used in JWT diff --git a/server/link.go b/server/link.go index 67a3eefd..00ac0be9 100644 --- a/server/link.go +++ b/server/link.go @@ -32,7 +32,7 @@ func (sl *SSHLinker) TokenCreated(token charm.Token) { } // TokenSent implements the proto.LinkTransport interface for the SSHLinker. -func (sl *SSHLinker) TokenSent(l *charm.Link) { +func (sl *SSHLinker) TokenSent(_ *charm.Link) { log.Debug("Token sent") } diff --git a/server/server.go b/server/server.go index af1e637d..b69a9324 100644 --- a/server/server.go +++ b/server/server.go @@ -10,7 +10,7 @@ import ( "net/url" "path/filepath" - "github.com/caarlos0/env/v6" + env "github.com/caarlos0/env/v6" charm "github.com/charmbracelet/charm/proto" "github.com/charmbracelet/charm/server/db" "github.com/charmbracelet/charm/server/db/sqlite" diff --git a/server/ssh.go b/server/ssh.go index 8053c58f..2caaa41b 100644 --- a/server/ssh.go +++ b/server/ssh.go @@ -17,7 +17,7 @@ import ( "github.com/charmbracelet/wish" rm "github.com/charmbracelet/wish/recover" "github.com/gliderlabs/ssh" - "github.com/golang-jwt/jwt/v4" + jwt "github.com/golang-jwt/jwt/v4" ) // Session represents a Charm User's SSH session. @@ -104,7 +104,7 @@ func (me *SSHServer) sendJSON(s ssh.Session, o interface{}) error { return json.NewEncoder(s).Encode(o) } -func (me *SSHServer) authHandler(ctx ssh.Context, key ssh.PublicKey) bool { +func (me *SSHServer) authHandler(_ ssh.Context, _ ssh.PublicKey) bool { return true } diff --git a/server/storage/local/storage_test.go b/server/storage/local/storage_test.go index f84893f3..f6e2b1fb 100644 --- a/server/storage/local/storage_test.go +++ b/server/storage/local/storage_test.go @@ -20,7 +20,7 @@ func TestPut(t *testing.T) { t.Fatal(err) } - paths := []string{"/", "///"} + paths := []string{filepath.Join(string(os.PathSeparator), ""), filepath.Join(string(os.PathSeparator), "//")} for _, path := range paths { err = lfs.Put(charmID, path, buf, fs.FileMode(0o644)) if err == nil { @@ -30,7 +30,7 @@ func TestPut(t *testing.T) { } content := "hello world" - path := "/hello.txt" + path := filepath.Join(string(os.PathSeparator), "hello.txt") t.Run(path, func(t *testing.T) { buf = bytes.NewBufferString(content) err = lfs.Put(charmID, path, buf, fs.FileMode(0o644)) @@ -63,7 +63,7 @@ func TestPut(t *testing.T) { }) content = "bar" - path = "/foo/hello.txt" + path = filepath.Join(string(os.PathSeparator), "foo", "hello.txt") t.Run(path, func(t *testing.T) { buf = bytes.NewBufferString(content) err = lfs.Put(charmID, path, buf, fs.FileMode(0o644)) diff --git a/ui/common/common.go b/ui/common/common.go index c4dbb262..e7ca431d 100644 --- a/ui/common/common.go +++ b/ui/common/common.go @@ -4,7 +4,7 @@ import ( "os" "sync" - "github.com/mattn/go-isatty" + isatty "github.com/mattn/go-isatty" ) var ( diff --git a/ui/common/views.go b/ui/common/views.go index d01cfcb5..fd23d957 100644 --- a/ui/common/views.go +++ b/ui/common/views.go @@ -52,7 +52,7 @@ var ( // NewSpinner returns a spinner model. func NewSpinner() spinner.Model { - s := spinner.NewModel() + s := spinner.New() s.Spinner = spinner.Dot s.Style = spinnerStyle return s diff --git a/ui/keys/keys.go b/ui/keys/keys.go index 50a28dc0..252b905a 100644 --- a/ui/keys/keys.go +++ b/ui/keys/keys.go @@ -98,7 +98,7 @@ func (m *Model) SetCharmClient(cc *client.Client) { func NewModel(cfg *client.Config) Model { st := common.DefaultStyles() - p := pager.NewModel() + p := pager.New() p.PerPage = keysPerPage p.Type = pager.Dots p.InactiveDot = st.InactivePagination.Render("•") @@ -122,7 +122,7 @@ func NewModel(cfg *client.Config) Model { func (m Model) Init() tea.Cmd { return tea.Batch( charmclient.NewClient(m.cfg), - spinner.Tick, + m.spinner.Tick, ) } @@ -355,7 +355,7 @@ func LoadKeys(m Model) tea.Cmd { } return tea.Batch( fetchKeys(m.cc), - spinner.Tick, + m.spinner.Tick, ) } diff --git a/ui/link/link.go b/ui/link/link.go index d5ca9f85..999ab462 100644 --- a/ui/link/link.go +++ b/ui/link/link.go @@ -70,7 +70,7 @@ func newModel(cfg *client.Config, code string) model { func (m model) Init() tea.Cmd { return tea.Batch( charmclient.NewClient(m.cfg), - spinner.Tick, + m.spinner.Tick, ) } diff --git a/ui/link/linkhandler.go b/ui/link/linkhandler.go index 4cb030e2..ab26aef8 100644 --- a/ui/link/linkhandler.go +++ b/ui/link/linkhandler.go @@ -26,43 +26,43 @@ func newLinkHandler() *linkHandler { } } -func (lh *linkHandler) TokenCreated(l *charm.Link) { +func (lh *linkHandler) TokenCreated(_ *charm.Link) { // Not implemented for the link participant } -func (lh *linkHandler) TokenSent(l *charm.Link) { +func (lh *linkHandler) TokenSent(_ *charm.Link) { lh.tokenSent <- struct{}{} } -func (lh *linkHandler) ValidToken(l *charm.Link) { +func (lh *linkHandler) ValidToken(_ *charm.Link) { lh.validToken <- true } -func (lh *linkHandler) InvalidToken(l *charm.Link) { +func (lh *linkHandler) InvalidToken(_ *charm.Link) { lh.validToken <- false } -func (lh *linkHandler) Request(l *charm.Link) bool { +func (lh *linkHandler) Request(_ *charm.Link) bool { // Not implemented for the link participant return false } -func (lh *linkHandler) RequestDenied(l *charm.Link) { +func (lh *linkHandler) RequestDenied(_ *charm.Link) { lh.requestDenied <- struct{}{} } -func (lh *linkHandler) SameUser(l *charm.Link) { +func (lh *linkHandler) SameUser(_ *charm.Link) { lh.success <- true } -func (lh *linkHandler) Success(l *charm.Link) { +func (lh *linkHandler) Success(_ *charm.Link) { lh.success <- false } -func (lh *linkHandler) Timeout(l *charm.Link) { +func (lh *linkHandler) Timeout(_ *charm.Link) { lh.timeout <- struct{}{} } -func (lh *linkHandler) Error(l *charm.Link) { +func (lh *linkHandler) Error(_ *charm.Link) { lh.err <- errors.New("error") } diff --git a/ui/linkgen/linkgen.go b/ui/linkgen/linkgen.go index 79996961..ce6d2c00 100644 --- a/ui/linkgen/linkgen.go +++ b/ui/linkgen/linkgen.go @@ -122,7 +122,7 @@ func (m *Model) SetCharmClient(cc *client.Client) { // Init is the Bubble Tea program's initialization function. This is used in // standalone mode. func (m Model) Init() tea.Cmd { - return tea.Batch(charmclient.NewClient(m.cfg), spinner.Tick) + return tea.Batch(charmclient.NewClient(m.cfg), m.spinner.Tick) } // Update is the Tea update loop. @@ -315,7 +315,7 @@ func (m Model) View() string { // InitLinkGen runs the necessary commands for starting the link generation // process. func InitLinkGen(m Model) tea.Cmd { - return tea.Batch(append(HandleLinkRequest(m), spinner.Tick)...) + return tea.Batch(append(HandleLinkRequest(m), m.spinner.Tick)...) } // HandleLinkRequest returns a bunch of blocking commands that resolve on link diff --git a/ui/linkgen/linkhandler.go b/ui/linkgen/linkhandler.go index afc26908..ccb876b8 100644 --- a/ui/linkgen/linkhandler.go +++ b/ui/linkgen/linkhandler.go @@ -26,11 +26,11 @@ func (lh *linkHandler) TokenCreated(l *charm.Link) { lh.token <- l.Token } -func (lh *linkHandler) TokenSent(l *charm.Link) {} +func (lh *linkHandler) TokenSent(_ *charm.Link) {} -func (lh *linkHandler) ValidToken(l *charm.Link) {} +func (lh *linkHandler) ValidToken(_ *charm.Link) {} -func (lh *linkHandler) InvalidToken(l *charm.Link) {} +func (lh *linkHandler) InvalidToken(_ *charm.Link) {} // Request handles link approvals. The remote machine sends an approval request, // which we send to the Tea UI as a message. The Tea application then sends a @@ -40,21 +40,21 @@ func (lh *linkHandler) Request(l *charm.Link) bool { return <-lh.response } -func (lh *linkHandler) RequestDenied(l *charm.Link) {} +func (lh *linkHandler) RequestDenied(_ *charm.Link) {} // Successful link, but this account has already been linked. -func (lh *linkHandler) SameUser(l *charm.Link) { +func (lh *linkHandler) SameUser(_ *charm.Link) { lh.success <- true } -func (lh *linkHandler) Success(l *charm.Link) { +func (lh *linkHandler) Success(_ *charm.Link) { lh.success <- false } -func (lh *linkHandler) Timeout(l *charm.Link) { +func (lh *linkHandler) Timeout(_ *charm.Link) { lh.timeout <- struct{}{} } -func (lh *linkHandler) Error(l *charm.Link) { +func (lh *linkHandler) Error(_ *charm.Link) { lh.err <- errors.New("there’s been an error; please try again") } diff --git a/ui/ui.go b/ui/ui.go index 4a172d72..8c6adce6 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -119,7 +119,7 @@ func initialModel(cfg *client.Config) model { func (m model) Init() tea.Cmd { return tea.Batch( charmclient.NewClient(m.cfg), - spinner.Tick, + m.spinner.Tick, ) } diff --git a/ui/username/username.go b/ui/username/username.go index 4066aa90..d717aced 100644 --- a/ui/username/username.go +++ b/ui/username/username.go @@ -92,7 +92,7 @@ func (m *Model) indexBackward() { func NewModel(cc *client.Client) Model { st := common.DefaultStyles() - im := input.NewModel() + im := input.New() im.CursorStyle = st.Cursor im.Placeholder = "divagurl2000" im.Prompt = st.FocusedPrompt.String() @@ -175,7 +175,7 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) { return m, tea.Batch( setName(m), // fire off the command, too - spinner.Tick, + m.spinner.Tick, ) case cancelButton: // Exit this mini-app m.Done = true