mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
api: generate random jwt secret if not present, remove unused imports
This commit is contained in:
parent
4a2cc70b52
commit
2f24a1db41
2 changed files with 17 additions and 7 deletions
14
cmd/main.go
14
cmd/main.go
|
@ -2,16 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/yusing/go-proxy/internal"
|
"github.com/yusing/go-proxy/internal"
|
||||||
v1 "github.com/yusing/go-proxy/internal/api/v1"
|
|
||||||
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
||||||
"github.com/yusing/go-proxy/internal/api/v1/favicon"
|
"github.com/yusing/go-proxy/internal/api/v1/favicon"
|
||||||
"github.com/yusing/go-proxy/internal/api/v1/query"
|
"github.com/yusing/go-proxy/internal/api/v1/query"
|
||||||
|
@ -20,7 +15,7 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/gperr"
|
"github.com/yusing/go-proxy/internal/gperr"
|
||||||
"github.com/yusing/go-proxy/internal/homepage"
|
"github.com/yusing/go-proxy/internal/homepage"
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
"github.com/yusing/go-proxy/internal/net/http/middleware"
|
"github.com/yusing/go-proxy/internal/net/gphttp/middleware"
|
||||||
"github.com/yusing/go-proxy/internal/route/routes/routequery"
|
"github.com/yusing/go-proxy/internal/route/routes/routequery"
|
||||||
"github.com/yusing/go-proxy/internal/task"
|
"github.com/yusing/go-proxy/internal/task"
|
||||||
"github.com/yusing/go-proxy/pkg"
|
"github.com/yusing/go-proxy/pkg"
|
||||||
|
@ -84,6 +79,11 @@ func main() {
|
||||||
homepage.InitOverridesConfig,
|
homepage.InitOverridesConfig,
|
||||||
favicon.InitIconCache,
|
favicon.InitIconCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if common.APIJWTSecret == nil {
|
||||||
|
logging.Warn().Msg("API_JWT_SECRET is not set, using random key")
|
||||||
|
common.APIJWTSecret = common.RandomJWTKey()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.DiscardLogger()
|
logging.DiscardLogger()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -16,3 +17,12 @@ func decodeJWTKey(key string) []byte {
|
||||||
}
|
}
|
||||||
return bytes
|
return bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandomJWTKey() []byte {
|
||||||
|
key := make([]byte, 32)
|
||||||
|
_, err := rand.Read(key)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msg("failed to generate random jwt key")
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue