Remove authorization from list route (#1)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
environment: development
|
||||
host: 127.0.0.1
|
||||
port: 3000
|
||||
auth_key: ""
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
|
||||
@@ -13,7 +13,6 @@ var (
|
||||
Environment: "development",
|
||||
Host: "127.0.0.1",
|
||||
Port: 3001,
|
||||
AuthKey: "",
|
||||
Redis: RedisConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 6379,
|
||||
@@ -96,7 +95,6 @@ type Config struct {
|
||||
Environment string `yaml:"environment"`
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
AuthKey string `yaml:"auth_key"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Routes RoutesConfig `yaml:"routes"`
|
||||
Cache CacheConfig `yaml:"cache"`
|
||||
|
||||
20
src/main.go
20
src/main.go
@@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
@@ -22,6 +24,7 @@ var (
|
||||
})
|
||||
r *Redis = &Redis{}
|
||||
conf *Config = &Config{}
|
||||
instanceID uint16 = 0
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -51,17 +54,20 @@ func init() {
|
||||
TimeFormat: "2006/01/02 15:04:05",
|
||||
}))
|
||||
}
|
||||
|
||||
if instanceID, err = GetInstanceID(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer r.Close()
|
||||
|
||||
instanceID, err := GetInstanceID()
|
||||
go ListenAndServe(conf.Host, conf.Port+instanceID)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer app.Shutdown()
|
||||
|
||||
log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID)
|
||||
log.Fatal(app.Listen(fmt.Sprintf("%s:%d", conf.Host, conf.Port+instanceID)))
|
||||
s := make(chan os.Signal, 1)
|
||||
signal.Notify(s, os.Interrupt, syscall.SIGTERM)
|
||||
<-s
|
||||
}
|
||||
|
||||
@@ -31,16 +31,6 @@ func PingHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// ListHandler is the API handler used for the `/list` route.
|
||||
func ListHandler(ctx *fiber.Ctx) error {
|
||||
authKey := ctx.Get("Authorization")
|
||||
|
||||
if len(authKey) < 1 {
|
||||
return ctx.SendStatus(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
if authKey != conf.AuthKey {
|
||||
return ctx.SendStatus(http.StatusForbidden)
|
||||
}
|
||||
|
||||
result := make([]string, 0)
|
||||
|
||||
var (
|
||||
|
||||
14
src/server.go
Normal file
14
src/server.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
func ListenAndServe(host string, port uint16) {
|
||||
log.Printf("Listening on %s:%d\n", host, port)
|
||||
|
||||
if err := app.Listen(fmt.Sprintf("%s:%d", host, port)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user