add transport address from env variable

This commit is contained in:
Yavolte 2025-06-17 18:39:40 +08:00
parent f5687a0094
commit 0bc3f9d170
4 changed files with 22 additions and 2 deletions

View File

@ -14,6 +14,14 @@ func (e *Error) Error() string {
return fmt.Sprintf("code: %d, message: %s", e.Code, e.Message) return fmt.Sprintf("code: %d, message: %s", e.Code, e.Message)
} }
func (e *Error) GetCode() int {
return e.Code
}
func (e *Error) GetMessage() string {
return e.Message
}
func Warp(code int, err error) error { func Warp(code int, err error) error {
return &Error{ return &Error{
Code: code, Code: code,

View File

@ -6,7 +6,9 @@ import (
"math" "math"
"net" "net"
"net/url" "net/url"
"os"
"runtime" "runtime"
"strconv"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -243,6 +245,8 @@ func New(cbs ...Option) *Server {
uri: &url.URL{Scheme: "cli"}, uri: &url.URL{Scheme: "cli"},
router: newRouter(""), router: newRouter(""),
} }
port, _ := strconv.Atoi(os.Getenv("CLI_PORT"))
srv.opts.address = fmt.Sprintf(":%d", port)
for _, cb := range cbs { for _, cb := range cbs {
cb(srv.opts) cb(srv.opts)
} }

View File

@ -2,8 +2,11 @@ package grpc
import ( import (
"context" "context"
"fmt"
"net" "net"
"net/url" "net/url"
"os"
"strconv"
"git.nobla.cn/golang/aeus/metadata" "git.nobla.cn/golang/aeus/metadata"
"git.nobla.cn/golang/aeus/middleware" "git.nobla.cn/golang/aeus/middleware"
@ -136,7 +139,6 @@ func New(cbs ...Option) *Server {
opts: &options{ opts: &options{
network: "tcp", network: "tcp",
logger: logger.Default(), logger: logger.Default(),
address: ":0",
grpcOpts: make([]grpc.ServerOption, 0, 10), grpcOpts: make([]grpc.ServerOption, 0, 10),
}, },
uri: &url.URL{ uri: &url.URL{
@ -144,6 +146,8 @@ func New(cbs ...Option) *Server {
}, },
middlewares: make([]middleware.Middleware, 0, 10), middlewares: make([]middleware.Middleware, 0, 10),
} }
port, _ := strconv.Atoi(os.Getenv("GRPC_PORT"))
svr.opts.address = fmt.Sprintf(":%d", port)
for _, cb := range cbs { for _, cb := range cbs {
cb(svr.opts) cb(svr.opts)
} }

View File

@ -2,11 +2,14 @@ package http
import ( import (
"context" "context"
"fmt"
"net" "net"
"net/http" "net/http"
"net/http/pprof" "net/http/pprof"
"net/url" "net/url"
"os"
"path" "path"
"strconv"
"sync" "sync"
"time" "time"
@ -242,9 +245,10 @@ func New(cbs ...Option) *Server {
opts: &options{ opts: &options{
network: "tcp", network: "tcp",
logger: logger.Default(), logger: logger.Default(),
address: ":0",
}, },
} }
port, _ := strconv.Atoi(os.Getenv("HTTP_PORT"))
svr.opts.address = fmt.Sprintf(":%d", port)
for _, cb := range cbs { for _, cb := range cbs {
cb(svr.opts) cb(svr.opts)
} }