working commit

This commit is contained in:
2026-01-30 00:15:20 +02:00
parent 1efa93804d
commit 95aa086327
5 changed files with 221 additions and 19 deletions
+49 -8
View File
@@ -15,7 +15,11 @@ import (
const protocol = "tcp"
type ServiceParams struct {
Handler *handler.Handler
Handler *handler.Handler
X509Cert []byte
X509Key []byte
Portnum int64
Address string
}
type Service struct {
@@ -23,16 +27,23 @@ type Service struct {
rout *router.Router
logg *logger.Logger
address string
portnum int64
listen net.Listener
hsrv *http.Server
address string
portnum int64
x509cert []byte
x509key []byte
listen net.Listener
hsrv *http.Server
}
func NewService(params *ServiceParams) (*Service, error) {
var err error
svc := &Service{
hand: params.Handler,
hand: params.Handler,
x509cert: conf.X509Cert,
x509key: conf.X509Key,
portnum: conf.Portnum,
address: conf.Address,
}
svc.logg = logger.NewLogger("service")
return svc, err
@@ -55,8 +66,38 @@ func (svc *Service) Build() error {
svc.logg.Infof("%s\t%s", item.Method, item.RawPath)
}
listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
svc.listen, err = net.Listen(protocol, listenAddress)
const useTLS = true
if useTLS {
tlsCert, err := tls.X509KeyPair(svc.x509cert, 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)
if err != nil {
return err
}
}
//listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
//svc.listen, err = net.Listen(protocol, listenAddress)
svc.log.Infof("Service listening at %v", svc.listen.Addr())
svc.hsrv = &http.Server{
Handler: svc.rout,
}