Use upstream in host config

This commit is contained in:
Jamie Curnow
2023-01-06 11:42:02 +10:00
parent bc6825c148
commit 17a108f75f
6 changed files with 49 additions and 25 deletions

View File

@ -55,7 +55,7 @@ type Model struct {
Certificate *certificate.Model `json:"certificate,omitempty"`
NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"`
User *user.Model `json:"user,omitempty"`
Upstream *upstream.Model `json:"upstream,omitempty"`
Upstream upstream.Model `json:"upstream,omitempty"`
}
func (m *Model) getByQuery(query string, params []interface{}) error {
@ -119,7 +119,7 @@ func (m *Model) Expand(items []string) error {
if m.UpstreamID > 0 {
var u upstream.Model
u, err = upstream.GetByID(m.UpstreamID)
m.Upstream = &u
m.Upstream = u
}
if util.SliceContainsItem(items, "user") && m.ID > 0 {
@ -140,6 +140,12 @@ func (m *Model) Expand(items []string) error {
m.NginxTemplate = &templ
}
if util.SliceContainsItem(items, "upstream") && m.UpstreamID > 0 {
var ups upstream.Model
ups, err = upstream.GetByID(m.UpstreamID)
m.Upstream = ups
}
return err
}
@ -171,6 +177,7 @@ func (m *Model) GetTemplate() Template {
Status: m.Status,
ErrorMessage: m.ErrorMessage,
IsDisabled: m.IsDisabled,
Upstream: m.Upstream,
}
return t

View File

@ -1,13 +1,6 @@
package host
type TemplateUpstream struct {
Hostname string
Port int
BalanceMethod string
MaxFails int
FailTimeout int
AdvancedConfig string
}
import "npm/internal/entity/upstream"
// Template is the model given to the template parser, converted from the Model
type Template struct {
@ -34,5 +27,5 @@ type Template struct {
AdvancedConfig string
Status string
ErrorMessage string
Upstreams []TemplateUpstream
Upstream upstream.Model
}