mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
refactor(agent): streamline certificate and server handling in StartAgentServer function
This commit is contained in:
parent
be85633c32
commit
f661907268
1 changed files with 2 additions and 9 deletions
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -20,11 +19,8 @@ type Options struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartAgentServer(parent task.Parent, opt Options) {
|
func StartAgentServer(parent task.Parent, opt Options) {
|
||||||
t := parent.Subtask("agent_server")
|
|
||||||
|
|
||||||
caCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: opt.CACert.Certificate[0]})
|
|
||||||
caCertPool := x509.NewCertPool()
|
caCertPool := x509.NewCertPool()
|
||||||
caCertPool.AppendCertsFromPEM(caCertPEM)
|
caCertPool.AddCert(opt.CACert.Leaf)
|
||||||
|
|
||||||
// Configure TLS
|
// Configure TLS
|
||||||
tlsConfig := &tls.Config{
|
tlsConfig := &tls.Config{
|
||||||
|
@ -44,8 +40,5 @@ func StartAgentServer(parent task.Parent, opt Options) {
|
||||||
TLSConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
server.Start(t, agentServer, logger)
|
server.Start(parent, agentServer, logger)
|
||||||
t.OnCancel("stop", func() {
|
|
||||||
server.Stop(agentServer, logger)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue