Init: setup uptrace and swagger
This commit is contained in:
23
utils/getRemoteAddr.go
Normal file
23
utils/getRemoteAddr.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
func GetRemoteAddr(req bunrouter.Request) string {
|
||||
xForwardedFor := req.Header.Get("X-Forwarded-For")
|
||||
xRealIP := req.Header.Get("X-Real-IP")
|
||||
|
||||
if xForwardedFor != "" {
|
||||
return xForwardedFor
|
||||
}
|
||||
|
||||
if xRealIP != "" {
|
||||
return xRealIP
|
||||
}
|
||||
|
||||
host, _, _ := net.SplitHostPort(req.RemoteAddr)
|
||||
return host
|
||||
}
|
||||
1
utils/initDB.go
Normal file
1
utils/initDB.go
Normal file
@@ -0,0 +1 @@
|
||||
package utils
|
||||
24
utils/initMinIO.go
Normal file
24
utils/initMinIO.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
func InitMinIO(ctx context.Context, mc *minio.Client) error {
|
||||
MINIO_BUCKET := os.Getenv("MINIO_BUCKET")
|
||||
|
||||
err := mc.MakeBucket(ctx, MINIO_BUCKET, minio.MakeBucketOptions{
|
||||
Region: "us-east-1",
|
||||
})
|
||||
if err != nil {
|
||||
exists, errBucketExists := mc.BucketExists(ctx, MINIO_BUCKET)
|
||||
if errBucketExists != nil || !exists {
|
||||
return errBucketExists
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
14
utils/success.go
Normal file
14
utils/success.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Success(w http.ResponseWriter) error {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
_, err := io.WriteString(w,
|
||||
`{"code":200, "message": "success"}`+"\n")
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user