mirror of
https://github.com/elyby/chrly.git
synced 2024-11-23 05:33:18 +05:30
Resolve golangcibot issues
This commit is contained in:
parent
9946eae73b
commit
17f82ec6d3
@ -3,7 +3,9 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@ -35,3 +37,10 @@ func initConfig() {
|
||||
replacer := strings.NewReplacer(".", "_")
|
||||
viper.SetEnvKeyReplacer(replacer)
|
||||
}
|
||||
|
||||
func waitForExitSignal() os.Signal {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
return <-ch
|
||||
}
|
||||
|
18
cmd/serve.go
18
cmd/serve.go
@ -83,9 +83,21 @@ var serveCmd = &cobra.Command{
|
||||
Auth: &auth.JwtAuth{Key: []byte(viper.GetString("chrly.secret"))},
|
||||
}
|
||||
|
||||
if err := cfg.Run(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
||||
}
|
||||
finishChan := make(chan bool)
|
||||
go func() {
|
||||
if err := cfg.Run(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
||||
finishChan <- true
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
s := waitForExitSignal()
|
||||
logger.Info(fmt.Sprintf("Got signal: %v, exiting.", s))
|
||||
finishChan <- true
|
||||
}()
|
||||
|
||||
<-finishChan
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,21 @@ var workerCmd = &cobra.Command{
|
||||
Logger: logger,
|
||||
}
|
||||
|
||||
if err := cfg.Run(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
||||
}
|
||||
finishChan := make(chan bool)
|
||||
go func() {
|
||||
if err := cfg.Run(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Error in main(): %v", err))
|
||||
finishChan <- true
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
s := waitForExitSignal()
|
||||
logger.Info(fmt.Sprintf("Got signal: %v, exiting.", s))
|
||||
finishChan <- true
|
||||
}()
|
||||
|
||||
<-finishChan
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,13 @@ type filesStorage struct {
|
||||
|
||||
func (repository *filesStorage) FindByUsername(username string) (*model.Cape, error) {
|
||||
if username == "" {
|
||||
return nil, &http.CapeNotFoundError{username}
|
||||
return nil, &http.CapeNotFoundError{Who: username}
|
||||
}
|
||||
|
||||
capePath := path.Join(repository.path, strings.ToLower(username)+".png")
|
||||
file, err := os.Open(capePath)
|
||||
if err != nil {
|
||||
return nil, &http.CapeNotFoundError{username}
|
||||
return nil, &http.CapeNotFoundError{Who: username}
|
||||
}
|
||||
|
||||
return &model.Cape{
|
||||
|
@ -148,13 +148,13 @@ func (db *redisDb) StoreUuid(username string, uuid string) error {
|
||||
|
||||
func findByUsername(username string, conn util.Cmder) (*model.Skin, error) {
|
||||
if username == "" {
|
||||
return nil, &http.SkinNotFoundError{username}
|
||||
return nil, &http.SkinNotFoundError{Who: username}
|
||||
}
|
||||
|
||||
redisKey := buildUsernameKey(username)
|
||||
response := conn.Cmd("GET", redisKey)
|
||||
if !response.IsType(redis.Str) {
|
||||
return nil, &http.SkinNotFoundError{username}
|
||||
return nil, &http.SkinNotFoundError{Who: username}
|
||||
}
|
||||
|
||||
encodedResult, err := response.Bytes()
|
||||
@ -181,7 +181,7 @@ func findByUsername(username string, conn util.Cmder) (*model.Skin, error) {
|
||||
func findByUserId(id int, conn util.Cmder) (*model.Skin, error) {
|
||||
response := conn.Cmd("HGET", accountIdToUsernameKey, id)
|
||||
if !response.IsType(redis.Str) {
|
||||
return nil, &http.SkinNotFoundError{"unknown"}
|
||||
return nil, &http.SkinNotFoundError{Who: "unknown"}
|
||||
}
|
||||
|
||||
username, _ := response.Str()
|
||||
|
10
http/http.go
10
http/http.go
@ -3,9 +3,6 @@ package http
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func NotFound(response http.ResponseWriter, _ *http.Request) {
|
||||
@ -19,13 +16,6 @@ func NotFound(response http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = response.Write(data)
|
||||
}
|
||||
|
||||
func waitForSignal() os.Signal {
|
||||
ch := make(chan os.Signal)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func apiBadRequest(resp http.ResponseWriter, errorsPerField map[string][]string) {
|
||||
resp.WriteHeader(http.StatusBadRequest)
|
||||
resp.Header().Set("Content-Type", "application/json")
|
||||
|
@ -111,12 +111,7 @@ func (ctx *Skinsystem) Run() error {
|
||||
Handler: ctx.CreateHandler(),
|
||||
}
|
||||
|
||||
go server.Serve(listener)
|
||||
|
||||
s := waitForSignal()
|
||||
ctx.Logger.Info(fmt.Sprintf("Got signal: %v, exiting.", s))
|
||||
|
||||
return nil
|
||||
return server.Serve(listener)
|
||||
}
|
||||
|
||||
func (ctx *Skinsystem) CreateHandler() *mux.Router {
|
||||
@ -274,7 +269,7 @@ func (ctx *Skinsystem) Textures(response http.ResponseWriter, request *http.Requ
|
||||
|
||||
responseData, _ := json.Marshal(textures)
|
||||
response.Header().Set("Content-Type", "application/json")
|
||||
response.Write(responseData)
|
||||
_, _ = response.Write(responseData)
|
||||
}
|
||||
|
||||
func (ctx *Skinsystem) SignedTextures(response http.ResponseWriter, request *http.Request) {
|
||||
@ -315,7 +310,7 @@ func (ctx *Skinsystem) SignedTextures(response http.ResponseWriter, request *htt
|
||||
|
||||
responseJson, _ := json.Marshal(responseData)
|
||||
response.Header().Set("Content-Type", "application/json")
|
||||
response.Write(responseJson)
|
||||
_, _ = response.Write(responseJson)
|
||||
}
|
||||
|
||||
func (ctx *Skinsystem) PostSkin(resp http.ResponseWriter, req *http.Request) {
|
||||
|
@ -40,13 +40,7 @@ func (ctx *UUIDsWorker) Run() error {
|
||||
Handler: ctx.CreateHandler(),
|
||||
}
|
||||
|
||||
// noinspection GoUnhandledErrorResult
|
||||
go server.Serve(listener)
|
||||
|
||||
s := waitForSignal()
|
||||
ctx.Logger.Info(fmt.Sprintf("Got signal: %v, exiting.", s))
|
||||
|
||||
return nil
|
||||
return server.Serve(listener)
|
||||
}
|
||||
|
||||
func (ctx *UUIDsWorker) CreateHandler() http.Handler {
|
||||
|
Loading…
Reference in New Issue
Block a user