automatically go fmt on lint

This commit is contained in:
41666 2020-12-05 23:26:36 -05:00
parent 2e1e63a789
commit d93592f1a2
4 changed files with 85 additions and 84 deletions

View file

@ -15,6 +15,7 @@
"scripts": { "scripts": {
"lint": "run-p -c lint:* --", "lint": "run-p -c lint:* --",
"lint:eslint": "eslint", "lint:eslint": "eslint",
"lint:go": "go fmt ./...",
"lint:prettier": "cross-env prettier -c '**/*.{ts,tsx,css,yml,yaml,md,json,js,jsx,sh,gitignore,mdx,Dockerfile}'", "lint:prettier": "cross-env prettier -c '**/*.{ts,tsx,css,yml,yaml,md,json,js,jsx,sh,gitignore,mdx,Dockerfile}'",
"lint:stylelint": "cross-env stylelint '**/*.{ts,tsx}'", "lint:stylelint": "cross-env stylelint '**/*.{ts,tsx}'",
"lint:types": "tsc --noEmit", "lint:types": "tsc --noEmit",

View file

@ -1,21 +1,21 @@
package version package version
import ( import (
"fmt" "fmt"
) )
var ( var (
GitCommit = "unknown" GitCommit = "unknown"
GitBranch = "unknown" GitBranch = "unknown"
BuildDate = "unknown" BuildDate = "unknown"
) )
func StartupInfo(serviceName string) string { func StartupInfo(serviceName string) string {
return fmt.Sprintf( return fmt.Sprintf(
"Starting %s service.\n Build %s (%s) at %s", "Starting %s service.\n Build %s (%s) at %s",
serviceName, serviceName,
GitCommit, GitCommit,
GitBranch, GitBranch,
BuildDate, BuildDate,
) )
} }

View file

@ -1,18 +1,18 @@
package version package version
import ( import (
"testing" "testing"
"time" "time"
) )
func TestStartup(t *testing.T) { func TestStartup(t *testing.T) {
GitBranch = "test" GitBranch = "test"
GitCommit = "e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e" GitCommit = "e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"
BuildDate = time.Now().UTC().Format("2006-01-02T15:04:05.000Z") BuildDate = time.Now().UTC().Format("2006-01-02T15:04:05.000Z")
expected := "Starting test service.\n Build e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e (test) at " + BuildDate expected := "Starting test service.\n Build e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e (test) at " + BuildDate
value := StartupInfo("test") value := StartupInfo("test")
if value != expected { if value != expected {
t.Error("Incorrect render, got `", value, "`") t.Error("Incorrect render, got `", value, "`")
} }
} }

View file

@ -1,45 +1,45 @@
package main package main
import ( import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
"github.com/roleypoly/roleypoly/src/common" "github.com/roleypoly/roleypoly/src/common"
"github.com/roleypoly/roleypoly/src/common/bot" "github.com/roleypoly/roleypoly/src/common/bot"
"github.com/roleypoly/roleypoly/src/common/version" "github.com/roleypoly/roleypoly/src/common/version"
"k8s.io/klog" "k8s.io/klog"
) )
var ( var (
botToken = common.Getenv("BOT_TOKEN").String() botToken = common.Getenv("BOT_TOKEN").String()
botClientID = common.Getenv("BOT_CLIENT_ID").String() botClientID = common.Getenv("BOT_CLIENT_ID").String()
rootUsers = common.Getenv("ROOT_USERS").StringSlice() rootUsers = common.Getenv("ROOT_USERS").StringSlice()
allowedBots = common.Getenv("ALLOWED_BOTS").StringSlice() allowedBots = common.Getenv("ALLOWED_BOTS").StringSlice()
appURL = common.Getenv("UI_PUBLIC_URI").SafeURL() appURL = common.Getenv("UI_PUBLIC_URI").SafeURL()
selfMention = bot.MentionMatcher(botClientID) selfMention = bot.MentionMatcher(botClientID)
) )
func main() { func main() {
klog.Info(version.StartupInfo("discord-bot")) klog.Info(version.StartupInfo("discord-bot"))
err := bot.ScaffoldBot(bot.BotScaffolding{ err := bot.ScaffoldBot(bot.BotScaffolding{
RootUsers: rootUsers, RootUsers: rootUsers,
AllowBots: true, AllowBots: true,
BotClientID: botClientID, BotClientID: botClientID,
BotToken: botToken, BotToken: botToken,
GatewayIntents: discordgo.IntentsGuildMessages, GatewayIntents: discordgo.IntentsGuildMessages,
Handler: handle, Handler: handle,
}) })
if err != nil { if err != nil {
klog.Fatal(err) klog.Fatal(err)
} }
} }
func isBotAllowlisted(userID string) bool { func isBotAllowlisted(userID string) bool {
for _, id := range allowedBots { for _, id := range allowedBots {
if id == userID { if id == userID {
return true return true
} }
} }
return false return false
} }