upgrade to go 1.18.

This commit is contained in:
Miroslav Šedivý
2022-08-02 00:37:20 +02:00
parent b744d491db
commit 917dea5cbb
5 changed files with 31 additions and 36 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ RUN npm run build
#
# STAGE 2: build executable binary
#
FROM golang:1.17-buster as builder
FROM golang:1.18-buster as builder
WORKDIR /app
COPY . .
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/m1k1o/neko-rooms
go 1.17
go 1.18
require (
github.com/Microsoft/go-winio v0.5.2 // indirect
+3 -3
View File
@@ -23,7 +23,7 @@ type ProxyManagerCtx struct {
client *dockerClient.Client
instanceName string
handlers *prefixHandler
handlers *prefixHandler[*httputil.ReverseProxy]
}
func New(client *dockerClient.Client, instanceName string) *ProxyManagerCtx {
@@ -32,7 +32,7 @@ func New(client *dockerClient.Client, instanceName string) *ProxyManagerCtx {
client: client,
instanceName: instanceName,
handlers: &prefixHandler{},
handlers: &prefixHandler[*httputil.ReverseProxy]{},
}
}
@@ -118,7 +118,7 @@ func (p *ProxyManagerCtx) Refresh() error {
return err
}
p.handlers = &prefixHandler{}
p.handlers = &prefixHandler[*httputil.ReverseProxy]{}
for _, cont := range containers {
path, port, ok := p.parseLabels(cont.Labels)
+20 -15
View File
@@ -1,16 +1,19 @@
package proxy
import (
"net/http/httputil"
"strings"
)
type prefixHandler struct {
Value *httputil.ReverseProxy
Children map[string]*prefixHandler
type prefixHandler[T any] struct {
Value T
Children map[string]*prefixHandler[T]
}
func (p *prefixHandler) Set(prefix string, value *httputil.ReverseProxy) {
func NewPrefixHandler[T any]() *prefixHandler[T] {
return &prefixHandler[T]{}
}
func (p *prefixHandler[T]) Set(prefix string, value T) {
arr := strings.Split(prefix, "/")
len := len(arr)
@@ -20,12 +23,12 @@ func (p *prefixHandler) Set(prefix string, value *httputil.ReverseProxy) {
}
if p.Children == nil {
p.Children = map[string]*prefixHandler{}
p.Children = map[string]*prefixHandler[T]{}
}
dat, ok := p.Children[a]
if !ok {
dat = &prefixHandler{}
dat = &prefixHandler[T]{}
}
if i == len-1 {
@@ -38,7 +41,7 @@ func (p *prefixHandler) Set(prefix string, value *httputil.ReverseProxy) {
}
}
func (p *prefixHandler) Remove(prefix string) {
func (p *prefixHandler[T]) Remove(prefix string) {
arr := strings.Split(prefix, "/")
len := len(arr)
@@ -61,7 +64,7 @@ func (p *prefixHandler) Remove(prefix string) {
// TODO: Remove all empty references.
}
func (p *prefixHandler) Match(path string) (*httputil.ReverseProxy, string, bool) {
func (p *prefixHandler[T]) Match(path string) (value T, prefix string, ok bool) {
arr := strings.Split(path, "/")
prefixArr := []string{}
@@ -70,9 +73,9 @@ func (p *prefixHandler) Match(path string) (*httputil.ReverseProxy, string, bool
continue
}
pointer, ok := p.Children[a]
if !ok {
return nil, "", false
pointer, found := p.Children[a]
if !found {
return
}
p = pointer
@@ -86,9 +89,11 @@ func (p *prefixHandler) Match(path string) (*httputil.ReverseProxy, string, bool
// if not leaf node
if p.Children != nil {
return nil, "", false
return
}
prefix := "/" + strings.Join(prefixArr, "/")
return p.Value, prefix, true
value = p.Value
prefix = "/" + strings.Join(prefixArr, "/")
ok = true
return
}
+5 -15
View File
@@ -1,24 +1,14 @@
package utils
import (
"reflect"
)
func ArrayIn[T comparable](val T, array []T) (exists bool, index int) {
exists, index = false, -1
func ArrayIn(val interface{}, array interface{}) (exists bool, index int) {
exists = false
index = -1
switch reflect.TypeOf(array).Kind() {
case reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
if reflect.DeepEqual(val, s.Index(i).Interface()) {
index = i
exists = true
for i, a := range array {
if a == val {
exists, index = true, i
return
}
}
}
return
}