register fix
This commit is contained in:
parent
e5c95b0476
commit
65dbbc16df
@ -5,7 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
consul "github.com/hashicorp/consul/api"
|
consul "github.com/hashicorp/consul/api"
|
||||||
@ -14,8 +13,8 @@ import (
|
|||||||
type Service struct {
|
type Service struct {
|
||||||
AppID string
|
AppID string
|
||||||
Name string
|
Name string
|
||||||
|
Domain string
|
||||||
Address string
|
Address string
|
||||||
IP string
|
|
||||||
Port int
|
Port int
|
||||||
TTL time.Duration
|
TTL time.Duration
|
||||||
ConsulAgent *consul.Agent
|
ConsulAgent *consul.Agent
|
||||||
@ -23,12 +22,12 @@ type Service struct {
|
|||||||
|
|
||||||
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
||||||
|
|
||||||
func NewService(servAddr, id, appName, ip, domain string, appPort int) (*Service, error) {
|
func NewService(servAddr, id, name, hostname, domain string, appPort int) (*Service, error) {
|
||||||
s := new(Service)
|
s := new(Service)
|
||||||
s.AppID = id
|
s.AppID = id
|
||||||
s.Name = strings.Replace(appName, "-", "", -1)
|
s.Name = name
|
||||||
s.Address = domain
|
s.Address = hostname
|
||||||
s.IP = ip
|
s.Domain = domain
|
||||||
s.Port = appPort
|
s.Port = appPort
|
||||||
s.TTL = time.Second * 15
|
s.TTL = time.Second * 15
|
||||||
|
|
||||||
@ -58,14 +57,14 @@ func (s *Service) GetID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetFullAddr() string {
|
func (s *Service) GetFullAddr() string {
|
||||||
return fmt.Sprintf("http://%s:%d/", s.IP, s.Port)
|
return fmt.Sprintf("http://%s:%d/", s.Address, s.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Register() error {
|
func (s *Service) Register() error {
|
||||||
def := &consul.AgentServiceRegistration{
|
def := &consul.AgentServiceRegistration{
|
||||||
ID: s.GetID(),
|
ID: s.GetID(),
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Address: s.IP,
|
Address: s.Address,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
Tags: s.getTags(),
|
Tags: s.getTags(),
|
||||||
Meta: s.getMetadata(),
|
Meta: s.getMetadata(),
|
||||||
@ -146,7 +145,7 @@ func (s *Service) getTags() []string {
|
|||||||
|
|
||||||
tags := []string{
|
tags := []string{
|
||||||
"traefik.enable=true",
|
"traefik.enable=true",
|
||||||
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.Address + "`)",
|
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.Domain + "`)",
|
||||||
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
"traefik.http.routers." + s.Name + ".entryPoints=https",
|
||||||
"traefik.http.routers." + s.Name + ".tls=true",
|
"traefik.http.routers." + s.Name + ".tls=true",
|
||||||
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
"traefik.http.routers." + s.Name + ".service=" + s.Name,
|
||||||
|
Loading…
Reference in New Issue
Block a user