Skip to content

Commit

Permalink
internal
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpristas committed Nov 11, 2021
1 parent 12c7d5d commit 7bc02be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions internal/pkg/config/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ type Endpoint struct {

// Server is the configuration for the server
type Server struct {
Host string `config:"host"` // TODO: deprecated use Endpoints
Port uint16 `config:"port"` // TODO: deprecated use Endpoints
Endpoints []Endpoint `config:"endpoints"`
Host string `config:"host"`
Port uint16 `config:"port"`
InternalHost string `config:"internal_host"`
InternalPort uint16 `config:"internal_port"`
TLS *tlscommon.ServerConfig `config:"ssl"`
Timeouts ServerTimeouts `config:"timeouts"`
Profiler ServerProfiler `config:"profiler"`
Expand All @@ -88,30 +89,31 @@ func (c *Server) InitDefaults() {

// BindEndpoints returns the binding address for the all HTTP server listeners.
func (c *Server) BindEndpoints() []string {
endpoints := map[string]bool{
c.BindAddress(): true,
}

// add each of the endpoints to collection,
for _, ep := range c.Endpoints {
e := bindAddress(ep.Host, ep.Port)
endpoints[e] = true
}
primaryAddress := c.BindAddress()
endpoints := make([]string, 0, 2)
endpoints = append(endpoints, primaryAddress)

// we need to get rid of duplicates so we dont have port collision
uniqueEndpoints := make([]string, 0, len(endpoints))
for ep := range endpoints {
uniqueEndpoints = append(uniqueEndpoints, ep)
if internalAddress := c.BindInternalAddress(); internalAddress != "" && internalAddress != primaryAddress {
endpoints = append(endpoints, internalAddress)
}

return uniqueEndpoints
return endpoints
}

// BindAddress returns the binding address for the HTTP server.
func (c *Server) BindAddress() string {
return bindAddress(c.Host, c.Port)
}

// BindInternalAddress returns the binding address for the internal HTTP server.
func (c *Server) BindInternalAddress() string {
if c.InternalPort <= 0 {
return ""
}

return bindAddress(c.InternalHost, c.InternalPort)
}

func bindAddress(host string, port uint16) string {
if strings.Count(host, ":") > 1 && strings.Count(host, "]") == 0 {
host = "[" + host + "]"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/elastic/fleet-server/v7/internal/pkg/build"
)

const defaultVersion = "7.16.0"
const defaultVersion = "7.15.0"

var (
Version string = defaultVersion
Expand Down

0 comments on commit 7bc02be

Please sign in to comment.