working commit

This commit is contained in:
2026-05-29 13:34:07 +02:00
parent bcdd2766e6
commit 4e2c548e97
15 changed files with 188 additions and 91 deletions
+12 -8
View File
@@ -30,9 +30,9 @@ type Service struct {
logg *logger.Logger
hsrv *http.Server
listen net.Listener
address string
portnum uint32
listen net.Listener
x509cert string
x509key string
protocol string
@@ -46,7 +46,7 @@ func NewService(params *ServiceParams) (*Service, error) {
portnum: params.Portnum,
x509cert: params.X509cert,
x509key: params.X509key,
protocol: "TCP",
protocol: "tcp",
}
svc.logg = logger.NewLoggerWithSubject("service")
return svc, err
@@ -54,7 +54,7 @@ func NewService(params *ServiceParams) (*Service, error) {
func (svc *Service) Build() error {
var err error
svc.logg.Infof("Service build ")
svc.logg.Infof("Service build")
svc.rout = router.NewRouter()
@@ -64,7 +64,14 @@ func (svc *Service) Build() error {
svc.rout.Use(svc.hand.AuthMiddleware)
svc.rout.Get(`/v3/api/service/hello`, svc.hand.SendHello)
svc.rout.Connect(`{hostaddr}`, svc.hand.ConnectTo)
svc.rout.Connect(``, svc.hand.ConnectTo)
svc.rout.Delete(`{uri:.*}`, svc.hand.PlainCall)
svc.rout.Get(`{uri:.*}`, svc.hand.PlainCall)
svc.rout.Head(`{uri:.*}`, svc.hand.PlainCall)
svc.rout.Patch(`{uri:.*}`, svc.hand.PlainCall)
svc.rout.Post(`{uri:.*}`, svc.hand.PlainCall)
svc.rout.NotFound(svc.hand.NotFound)
@@ -73,26 +80,23 @@ func (svc *Service) Build() error {
svc.logg.Infof("%s\t%s", item.Method, item.RawPath)
}
const useTLS = true
const useTLS = false
if useTLS {
tlsCert, err := tls.X509KeyPair([]byte(svc.x509cert), []byte(svc.x509key))
if err != nil {
return err
}
tlsConfig := tls.Config{
Certificates: []tls.Certificate{tlsCert},
ClientAuth: tls.NoClientCert,
InsecureSkipVerify: true,
}
listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
svc.listen, err = tls.Listen(svc.protocol, listenAddress, &tlsConfig)
if err != nil {
return err
}
} else {
listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
svc.listen, err = net.Listen(svc.protocol, listenAddress)