mirror of
https://gitea.com/jonasfranz/staletea
synced 2024-05-09 11:46:06 +02:00
Add linters
This commit is contained in:
parent
becfef8ebc
commit
1149c45437
|
@ -0,0 +1,9 @@
|
|||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: golang:1.12
|
||||
commands:
|
||||
- make lint
|
||||
- make golangci-lint
|
|
@ -0,0 +1,25 @@
|
|||
linters:
|
||||
enable:
|
||||
- gosimple
|
||||
- deadcode
|
||||
- typecheck
|
||||
- govet
|
||||
- errcheck
|
||||
- staticcheck
|
||||
- unused
|
||||
- structcheck
|
||||
- varcheck
|
||||
- golint
|
||||
- dupl
|
||||
- gofmt
|
||||
- misspell
|
||||
- gocritic
|
||||
enable-all: false
|
||||
disable-all: true
|
||||
fast: false
|
||||
|
||||
linters-settings:
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- ifElseChain
|
||||
- singleCaseSwitch # Every time this occured in the code, there was no other way.
|
|
@ -0,0 +1,13 @@
|
|||
.PHONY: golangci-lint
|
||||
golangci-lint:
|
||||
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.16.0; \
|
||||
fi
|
||||
golangci-lint run
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go get -u golang.org/x/lint/golint; \
|
||||
fi
|
||||
golint ./...
|
11
cmd/run.go
11
cmd/run.go
|
@ -1,11 +1,11 @@
|
|||
// staletea
|
||||
// Copyright (C) 2019 Jonas Franz
|
||||
//
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
|
@ -21,12 +21,13 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// CmdRun is the command to start the webserver
|
||||
var CmdRun = cli.Command{
|
||||
Action: run,
|
||||
Name: "run",
|
||||
Name: "run",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "address",
|
||||
Name: "address",
|
||||
Value: ":3030",
|
||||
},
|
||||
},
|
||||
|
@ -34,4 +35,4 @@ var CmdRun = cli.Command{
|
|||
|
||||
func run(ctx *cli.Context) error {
|
||||
return web.StartServer(ctx.String("address"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ func (k Key) setDefault(defaultValue interface{}) {
|
|||
viper.SetDefault(string(k), defaultValue)
|
||||
}
|
||||
|
||||
// This block contains all config keys
|
||||
const (
|
||||
DaysUntilStale Key = "daysUntilStale"
|
||||
DaysUntilClose Key = "daysUntilClose"
|
||||
|
@ -61,6 +62,7 @@ const (
|
|||
SessionSecret Key = "session_secret"
|
||||
)
|
||||
|
||||
// SetupConfig fills all default values, reads the config and/or writes the default config.
|
||||
func SetupConfig() error {
|
||||
DaysUntilStale.setDefault(60)
|
||||
DaysUntilClose.setDefault(7)
|
||||
|
@ -90,7 +92,9 @@ func SetupConfig() error {
|
|||
viper.AddConfigPath(".")
|
||||
if err := viper.SafeWriteConfigAs("config.yml"); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
err = viper.WriteConfigAs("config.yml")
|
||||
if err := viper.WriteConfigAs("config.yml"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return viper.ReadInConfig()
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package models
|
||||
|
||||
// Repository represents a Gitea repository indexed at the local database
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk"`
|
||||
Owner string `xorm:"unique(owner_name)"`
|
||||
|
|
|
@ -18,6 +18,7 @@ package models
|
|||
|
||||
import "golang.org/x/oauth2"
|
||||
|
||||
// User represents a signed in oauth2 gitea user saved in a session
|
||||
type User struct {
|
||||
ID int64
|
||||
Username string
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/base64"
|
||||
)
|
||||
|
||||
// NewSecret will generate a random string of the given length
|
||||
func NewSecret(length int) (string, error) {
|
||||
secret := make([]byte, length)
|
||||
if _, err := rand.Read(secret); err != nil {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// StartServer will start the webserver at the given addresses
|
||||
func StartServer(addr ...string) error {
|
||||
r := gin.Default()
|
||||
store := cookie.NewStore([]byte(config.SessionSecret.Get().(string)))
|
||||
|
|
Loading…
Reference in New Issue