mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-03 15:56:22 +00:00
⚡ initialize project structure with main, routing, and environment utilities
This commit is contained in:
0
Dockerfile
Normal file
0
Dockerfile
Normal file
3
cmd/server/main.go
Normal file
3
cmd/server/main.go
Normal file
@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
func main() {}
|
15
internal/router/router.go
Normal file
15
internal/router/router.go
Normal file
@ -0,0 +1,15 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
v1 "github.com/snowykami/neo-blog/internal/router/v1"
|
||||
"github.com/snowykami/neo-blog/pkg/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
h := server.New(
|
||||
server.WithHostPorts(":"+utils.Getenv("PORT", "8888")),
|
||||
server.WithMaxRequestBodySize(utils.GetenvAsInt("MAX_REQUEST_BODY_SIZE", 1048576000)), // 1000MiB
|
||||
)
|
||||
v1.RegisterRoutes()
|
||||
}
|
7
internal/router/v1/user.go
Normal file
7
internal/router/v1/user.go
Normal file
@ -0,0 +1,7 @@
|
||||
package v1
|
||||
|
||||
import "github.com/cloudwego/hertz/pkg/route"
|
||||
|
||||
func registerUserRoutes(group *route.RouterGroup) {
|
||||
|
||||
}
|
8
internal/router/v1/v1.go
Normal file
8
internal/router/v1/v1.go
Normal file
@ -0,0 +1,8 @@
|
||||
package v1
|
||||
|
||||
import "github.com/cloudwego/hertz/pkg/app/server"
|
||||
|
||||
func RegisterRoutes(h *server.Hertz) {
|
||||
apiV1Group := h.Group("/api/v1")
|
||||
registerUserRoutes(apiV1Group)
|
||||
}
|
46
pkg/utils/env.go
Normal file
46
pkg/utils/env.go
Normal file
@ -0,0 +1,46 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/joho/godotenv"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_ = godotenv.Load()
|
||||
}
|
||||
|
||||
func Getenv(key string, defaultValue ...string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" && len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetenvAsInt(key string, defaultValue ...int) int {
|
||||
value := os.Getenv(key)
|
||||
if value == "" && len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil && len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
return intValue
|
||||
}
|
||||
|
||||
func GetenvAsBool(key string, defaultValue ...bool) bool {
|
||||
value := os.Getenv(key)
|
||||
if value == "" && len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
boolValue, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
if len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
return false
|
||||
}
|
||||
return boolValue
|
||||
}
|
Reference in New Issue
Block a user