This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SetAlive for this backend | |
func (b *Backend) SetAlive(alive bool) { | |
b.mux.Lock() | |
b.Alive = alive | |
b.mux.Unlock() | |
} | |
// IsAlive returns true when backend is alive | |
func (b *Backend) IsAlive() (alive bool) { | |
b.mux.RLock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetNextPeer returns next active peer to take a connection | |
func (s *ServerPool) GetNextPeer() *Backend { | |
// loop entire backends to find out an Alive backend | |
next := s.NextIndex() | |
l := len(s.backends) + next // start from next and move a full cycle | |
for i := next; i < l; i++ { | |
idx := i % len(s.backends) // take an index by modding | |
if s.backends[idx].IsAlive() { // if we have an alive backend, use it and store if its not the original one | |
if i != next { | |
atomic.StoreUint64(&s.current, uint64(idx)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Backend struct { | |
URL *url.URL | |
Alive bool | |
mux sync.RWMutex | |
ReverseProxy *httputil.ReverseProxy | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+build ignore | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"go/format" | |
"io/ioutil" | |
"log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func FormatByteSlice(sl []byte) string { | |
builder := strings.Builder{} | |
for _, v := range sl { | |
builder.WriteString(fmt.Sprintf("%d,", int(v))) | |
} | |
return builder.String() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var packageTemplate = template.Must(template.New("").Funcs(map[string]interface{}{"conv": FormatByteSlice}).Parse(`// Code generated by go generate; DO NOT EDIT. | |
// generated using files from resources directory | |
// DO NOT COMMIT this file | |
package box | |
func init(){ | |
{{- range $name, $file := . }} | |
resources.Add("{{ $name }}", []byte{ {{ conv $file }} }) | |
{{- end }} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources := make(map[string][]byte) | |
err := filepath.Walk("resources", func(path string, info os.FileInfo, err error) error { | |
if err != nil { | |
log.Println("Error :", err) | |
return err | |
} | |
relativePath := filepath.ToSlash(strings.TrimPrefix(path, "resources")) | |
if info.IsDir() { | |
log.Println(path, "is a directory, skipping...") | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:generate go run gen.go | |
package box | |
type resourceBox struct { | |
storage map[string][]byte | |
} | |
func newResourceBox() *resourceBox { | |
return &resourceBox{storage: make(map[string][]byte)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define default values, other resources in default package | |
package defaults | |
var ConfigTemplate = []byte(` | |
// content goes here | |
`) | |
// In some another package | |
func somefunc(){ | |
ioutil.WriteFile("/path/to/dest", defaults.ConfigTemplate, os.ModePerm) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
environments: # Define environments as a list | |
- name: dev # Name of the environment | |
gatewayEnvironments: # define gateway environments | |
- "Production and Sandbox" # List gateways | |
- "Another Gateway" | |
certs: # define certificates for endpoints as a list | |
- hostName: 'https://dev.wso2.com' # hostname for the certificate | |
alias: 'Dev Certificate' # Alias for the certificate | |
path: '~/certs/dev.pem' # path to public certificate file | |
endpoints: # Define endpoints for environment |