From 8f550ede42c64e7e20162c0f32d4f33bd0f4b3cf Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 5 Oct 2023 16:21:33 +0900 Subject: [PATCH] Fix lint warn --- cli.go | 8 ++++---- config.go | 26 +++++++++++++------------- dewy.go | 8 ++++---- kvs/consul.go | 10 +++++----- kvs/file.go | 22 +++++++++++----------- kvs/kvs.go | 6 +++--- kvs/memory.go | 10 +++++----- kvs/redis.go | 10 +++++----- notice/notice.go | 8 ++++---- notice/slack.go | 18 +++++++++--------- repo/github_release.go | 20 +++++++++++--------- repo/repo.go | 14 +++++++------- starter.go | 22 +++++++++++----------- 13 files changed, 92 insertions(+), 90 deletions(-) diff --git a/cli.go b/cli.go index 62a6f3e..e9f3098 100644 --- a/cli.go +++ b/cli.go @@ -14,10 +14,10 @@ import ( ) const ( - // ExitOK for exit code + // ExitOK for exit code. ExitOK int = 0 - // ExitErr for exit code + // ExitErr for exit code. ExitErr int = 1 ) @@ -35,7 +35,7 @@ type cli struct { Version bool `long:"version" short:"v" description:"prints the version number"` } -// Env struct +// Env struct. type Env struct { Out, Err io.Writer Args []string @@ -44,7 +44,7 @@ type Env struct { Date string } -// RunCLI runs as cli +// RunCLI runs as cli. func RunCLI(env Env) int { cli := &cli{env: env, Interval: -1, PreRelease: false} return cli.run() diff --git a/config.go b/config.go index d2d1d24..5de7708 100644 --- a/config.go +++ b/config.go @@ -7,17 +7,17 @@ import ( "github.com/linyows/dewy/repo" ) -// Command for CLI +// Command for CLI. type Command int const ( - // SERVER command + // SERVER command. SERVER Command = iota - // ASSETS command + // ASSETS command. ASSETS ) -// String to string for Command +// String to string for Command. func (c Command) String() string { switch c { case SERVER: @@ -29,17 +29,17 @@ func (c Command) String() string { } } -// CacheType for cache type +// CacheType for cache type. type CacheType int const ( - // NONE cache type + // NONE cache type. NONE CacheType = iota - // FILE cache type + // FILE cache type. FILE ) -// String to string for CacheType +// String to string for CacheType. func (c CacheType) String() string { switch c { case NONE: @@ -51,13 +51,13 @@ func (c CacheType) String() string { } } -// CacheConfig struct +// CacheConfig struct. type CacheConfig struct { Type CacheType Expiration int } -// Config struct +// Config struct. type Config struct { Command Command Repository repo.Config @@ -65,10 +65,10 @@ type Config struct { Starter starter.Config } -// OverrideWithEnv overrides by environments +// OverrideWithEnv overrides by environments. func (c *Config) OverrideWithEnv() { if c.Repository.Provider == repo.GITHUB { - // Support env GITHUB_ENDPOINT + // Support env GITHUB_ENDPOINT. e := os.Getenv("GITHUB_ENDPOINT") if e != "" { os.Setenv("GITHUB_API_URL", e) @@ -80,7 +80,7 @@ func (c *Config) OverrideWithEnv() { } } -// DefaultConfig returns default Config +// DefaultConfig returns default Config. func DefaultConfig() Config { return Config{ Cache: CacheConfig{ diff --git a/dewy.go b/dewy.go index 0dbd1b0..d4feca7 100644 --- a/dewy.go +++ b/dewy.go @@ -29,7 +29,7 @@ const ( keepReleases = 7 ) -// Dewy struct +// Dewy struct. type Dewy struct { config Config registory registory.Registory @@ -42,7 +42,7 @@ type Dewy struct { sync.RWMutex } -// New returns Dewy +// New returns Dewy. func New(c Config) (*Dewy, error) { kv := &kvs.File{} kv.Default() @@ -67,7 +67,7 @@ func New(c Config) (*Dewy, error) { }, nil } -// Start dewy +// Start dewy. func (d *Dewy) Start(i int) { ctx, cancel := context.WithCancel(context.WithValue(context.Background(), notice.MetaContextKey, true)) defer cancel() @@ -117,7 +117,7 @@ func (d *Dewy) waitSigs() os.Signal { return sigReceived } -// Run dewy +// Run dewy. func (d *Dewy) Run() error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/kvs/consul.go b/kvs/consul.go index c2a68c7..9570bda 100644 --- a/kvs/consul.go +++ b/kvs/consul.go @@ -1,6 +1,6 @@ package kvs -// Consul struct +// Consul struct. type Consul struct { items map[string]*item //nolint Host string @@ -8,18 +8,18 @@ type Consul struct { Password string } -// Read data on Consul +// Read data on Consul. func (c *Consul) Read(key string) { } -// Write data to Consul +// Write data to Consul. func (c *Consul) Write(data string) { } -// Delete data on Consul +// Delete data on Consul. func (c *Consul) Delete(key string) { } -// List returns key from Consul +// List returns key from Consul. func (c *Consul) List() { } diff --git a/kvs/file.go b/kvs/file.go index 22cda50..e7e25ad 100644 --- a/kvs/file.go +++ b/kvs/file.go @@ -12,9 +12,9 @@ import ( ) var ( - // DefaultTempDir creates temp dir + // DefaultTempDir creates temp dir. DefaultTempDir = createTempDir() - // DefaultMaxSize for data size + // DefaultMaxSize for data size. DefaultMaxSize int64 = 64 * 1024 * 1024 ) @@ -23,7 +23,7 @@ func createTempDir() string { return dir } -// File struct +// File struct. type File struct { items map[string]*item //nolint dir string @@ -32,18 +32,18 @@ type File struct { MaxSize int64 } -// GetDir returns dir +// GetDir returns dir. func (f *File) GetDir() string { return f.dir } -// Default sets to struct +// Default sets to struct. func (f *File) Default() { f.dir = DefaultTempDir f.MaxSize = DefaultMaxSize } -// Read data by key from file +// Read data by key from file. func (f *File) Read(key string) ([]byte, error) { p := filepath.Join(f.dir, key) if !IsFileExist(p) { @@ -58,7 +58,7 @@ func (f *File) Read(key string) ([]byte, error) { return content, nil } -// Write data to file +// Write data to file. func (f *File) Write(key string, data []byte) error { dirstat, err := os.Stat(f.dir) if err != nil { @@ -89,7 +89,7 @@ func (f *File) Write(key string, data []byte) error { return nil } -// Delete data on file +// Delete data on file. func (f *File) Delete(key string) error { p := filepath.Join(f.dir, key) if !IsFileExist(p) { @@ -103,7 +103,7 @@ func (f *File) Delete(key string) error { return nil } -// List returns keys from file +// List returns keys from file. func (f *File) List() ([]string, error) { files, err := os.ReadDir(f.dir) if err != nil { @@ -118,7 +118,7 @@ func (f *File) List() ([]string, error) { return list, nil } -// ExtractArchive extracts by archive +// ExtractArchive extracts by archive. func ExtractArchive(src, dst string) error { if !IsFileExist(src) { return fmt.Errorf("File not found: %s", src) @@ -127,7 +127,7 @@ func ExtractArchive(src, dst string) error { return archiver.Unarchive(src, dst) } -// IsFileExist checks file exists +// IsFileExist checks file exists. func IsFileExist(p string) bool { _, err := os.Stat(p) diff --git a/kvs/kvs.go b/kvs/kvs.go index 3035178..0d0546a 100644 --- a/kvs/kvs.go +++ b/kvs/kvs.go @@ -6,7 +6,7 @@ import ( "time" ) -// KVS interface +// KVS interface. type KVS interface { Read(key string) ([]byte, error) Write(key string, data []byte) error @@ -15,11 +15,11 @@ type KVS interface { GetDir() string } -// Config struct +// Config struct. type Config struct { } -// New returns KVS +// New returns KVS. func New(t string, c Config) (KVS, error) { switch t { case "file": diff --git a/kvs/memory.go b/kvs/memory.go index 6e88de5..253cec4 100644 --- a/kvs/memory.go +++ b/kvs/memory.go @@ -1,25 +1,25 @@ package kvs -// Memory struct +// Memory struct. type Memory struct { items map[string]*item //nolint } -// Read data by key on memory +// Read data by key on memory. func (m *Memory) Read(key string) string { return "" } -// Write data to memory +// Write data to memory. func (m *Memory) Write(data string) bool { return true } -// Delete data by key on memory +// Delete data by key on memory. func (m *Memory) Delete(key string) bool { return true } -// List returns keys from memory +// List returns keys from memory. func (m *Memory) List() { } diff --git a/kvs/redis.go b/kvs/redis.go index 73aadb4..92ab505 100644 --- a/kvs/redis.go +++ b/kvs/redis.go @@ -1,6 +1,6 @@ package kvs -// Redis struct +// Redis struct. type Redis struct { items map[string]*item //nolint Host string @@ -9,18 +9,18 @@ type Redis struct { TTL int } -// Read data by key on redis +// Read data by key on redis. func (r *Redis) Read(key string) { } -// Write data to redis +// Write data to redis. func (r *Redis) Write(data string) { } -// Delete key on redis +// Delete key on redis. func (r *Redis) Delete(key string) { } -// List returns keys from redis +// List returns keys from redis. func (r *Redis) List() { } diff --git a/notice/notice.go b/notice/notice.go index 10feca7..17501f8 100644 --- a/notice/notice.go +++ b/notice/notice.go @@ -7,20 +7,20 @@ import ( "os/user" ) -// Notice interface +// Notice interface. type Notice interface { String() string Notify(ctx context.Context, message string) } -// Field struct +// Field struct. type Field struct { Title string Value string Short bool } -// Config struct +// Config struct. type Config struct { Command string Source string @@ -31,7 +31,7 @@ type Config struct { RepoOwnerLink string } -// New returns Notice +// New returns Notice. func New(n Notice) (Notice, error) { switch n.String() { case "slack": diff --git a/notice/slack.go b/notice/slack.go index dd41a69..1296c28 100644 --- a/notice/slack.go +++ b/notice/slack.go @@ -2,7 +2,7 @@ package notice import ( "context" - "crypto/md5" + "crypto/md5" //nolint:gosec "fmt" "log" "os" @@ -15,22 +15,22 @@ import ( var ( defaultSlackChannel = "general" - // SlackUsername variable + // SlackUsername variable. SlackUsername = "Dewy" - // SlackIconURL variable + // SlackIconURL variable. SlackIconURL = "https://raw.githubusercontent.com/linyows/dewy/main/misc/dewy-icon.512.png" - // SlackFooter variable + // SlackFooter variable. SlackFooter = "Dewy notice/slack" - // SlackFooterIcon variable + // SlackFooterIcon variable. SlackFooterIcon = SlackIconURL ) type key int -// MetaContextKey for context key +// MetaContextKey for context key. const MetaContextKey key = iota -// Slack struct +// Slack struct. type Slack struct { Token string Channel string @@ -41,7 +41,7 @@ func (s *Slack) String() string { return "slack" } -// Notify posts message to Slack channel +// Notify posts message to Slack channel. func (s *Slack) Notify(ctx context.Context, message string) { if t := os.Getenv("SLACK_TOKEN"); t != "" { s.Token = t @@ -68,7 +68,7 @@ func (s *Slack) Notify(ctx context.Context, message string) { } func (s *Slack) genColor() string { - return strings.ToUpper(fmt.Sprintf("#%x", md5.Sum([]byte(hostname())))[0:7]) + return strings.ToUpper(fmt.Sprintf("#%x", md5.Sum([]byte(hostname())))[0:7]) //nolint:gosec } func (s *Slack) buildAttachment(message string, meta bool) objects.Attachment { diff --git a/repo/github_release.go b/repo/github_release.go index 83c5610..e8e367b 100644 --- a/repo/github_release.go +++ b/repo/github_release.go @@ -20,7 +20,7 @@ import ( const ( GitHubReleaseScheme = "github_release" - // ISO8601 for time format + // ISO8601 for time format. ISO8601 = "20060102T150405Z0700" ) @@ -30,7 +30,7 @@ var httpClient = &http.Client{ var _ Repo = (*GithubRelease)(nil) -// GithubRelease struct +// GithubRelease struct. type GithubRelease struct { baseURL string uploadURL string @@ -43,7 +43,7 @@ type GithubRelease struct { updatedAt github.Timestamp } -// NewGithubRelease returns GithubRelease +// NewGithubRelease returns GithubRelease. func NewGithubRelease(c Config) (*GithubRelease, error) { cl, err := factory.NewGithubClient() if err != nil { @@ -62,7 +62,7 @@ func NewGithubRelease(c Config) (*GithubRelease, error) { return g, nil } -// String to string +// String to string. func (g *GithubRelease) String() string { return g.host() } @@ -75,22 +75,22 @@ func (g *GithubRelease) host() string { return "github.com" } -// OwnerURL returns owner URL +// OwnerURL returns owner URL. func (g *GithubRelease) OwnerURL() string { return fmt.Sprintf("https://%s/%s", g, g.owner) } -// OwnerIconURL returns owner icon URL +// OwnerIconURL returns owner icon URL. func (g *GithubRelease) OwnerIconURL() string { return fmt.Sprintf("%s.png?size=200", g.OwnerURL()) } -// URL returns repository URL +// URL returns repository URL. func (g *GithubRelease) URL() string { return fmt.Sprintf("%s/%s", g.OwnerURL(), g.name) } -// ReleaseURL returns release URL +// Current returns current artifact. func (g *GithubRelease) Current(req *registory.CurrentRequest) (*registory.CurrentResponse, error) { release, err := g.latest() if err != nil { @@ -143,6 +143,7 @@ func (g *GithubRelease) latest() (*github.RepositoryRelease, error) { return r, nil } +// Fetch fetch artifact. func (g *GithubRelease) Fetch(url string, w io.Writer) error { ctx := context.Background() // github_release://owner/repo/tag/v1.0.0/artifact.zip @@ -194,7 +195,7 @@ L: return err } if url != "" { - res, err := http.Get(url) + res, err := httpClient.Get(url) if err != nil { return err } @@ -210,6 +211,7 @@ L: return nil } +// Report report shipping. func (g *GithubRelease) Report(req *registory.ReportRequest) error { if g.disableRecordShipping { return nil diff --git a/repo/repo.go b/repo/repo.go index 448d85b..25d54f6 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -8,7 +8,7 @@ import ( "github.com/linyows/dewy/storage" ) -// Repo interface for repository +// Repo interface for repository. type Repo interface { registory.Registory storage.Fetcher @@ -18,15 +18,15 @@ type Repo interface { URL() string } -// Provider for repository +// Provider for repository. type Provider int const ( - // GITHUB repository provider + // GITHUB repository provider. GITHUB Provider = iota ) -// String to string for Provider +// String to string for Provider. func (r Provider) String() string { switch r { case GITHUB: @@ -36,7 +36,7 @@ func (r Provider) String() string { } } -// Config struct +// Config struct. type Config struct { Provider Owner string @@ -46,12 +46,12 @@ type Config struct { DisableRecordShipping bool // FIXME: For testing. Remove this. } -// String to string for Config +// String to string for Config. func (c Config) String() string { return path.Join(c.Provider.String(), c.Owner, c.Name) } -// New returns repo +// New returns repo. func New(c Config) (Repo, error) { switch c.Provider { case GITHUB: diff --git a/starter.go b/starter.go index 4eaaad9..d0107d3 100644 --- a/starter.go +++ b/starter.go @@ -7,7 +7,7 @@ import ( starter "github.com/lestrrat-go/server-starter" ) -// StarterConfig struct +// StarterConfig struct. type StarterConfig struct { args []string command string @@ -21,32 +21,32 @@ type StarterConfig struct { statusfile string } -// Args for StarterConfig +// Args for StarterConfig. func (c StarterConfig) Args() []string { return c.args } -// Command for StarterConfig +// Command for StarterConfig. func (c StarterConfig) Command() string { return c.command } -// Dir for StarterConfig +// Dir for StarterConfig. func (c StarterConfig) Dir() string { return c.dir } -// Interval for StarterConfig +// Interval for StarterConfig. func (c StarterConfig) Interval() time.Duration { return time.Duration(c.interval) * time.Second } -// PidFile for StarterConfig +// PidFile for StarterConfig. func (c StarterConfig) PidFile() string { return c.pidfile } -// Ports for StarterConfig +// Ports for StarterConfig. func (c StarterConfig) Ports() []string { return c.ports } -// Paths for StarterConfig +// Paths for StarterConfig. func (c StarterConfig) Paths() []string { return c.paths } -// SignalOnHUP for StarterConfig +// SignalOnHUP for StarterConfig. func (c StarterConfig) SignalOnHUP() os.Signal { return starter.SigFromName(c.sigonhup) } -// SignalOnTERM for StarterConfig +// SignalOnTERM for StarterConfig. func (c StarterConfig) SignalOnTERM() os.Signal { return starter.SigFromName(c.sigonterm) } -// StatusFile for StarterConfig +// StatusFile for StarterConfig. func (c StarterConfig) StatusFile() string { return c.statusfile }