mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
small string split join optimization
This commit is contained in:
@@ -2,17 +2,17 @@ package types
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
)
|
||||
|
||||
func ValidateHTTPHeaders(headers map[string]string) (http.Header, E.Error) {
|
||||
h := make(http.Header)
|
||||
for k, v := range headers {
|
||||
vSplit := strings.Split(v, ",")
|
||||
vSplit := strutils.CommaSeperatedList(v)
|
||||
for _, header := range vSplit {
|
||||
h.Add(k, strings.TrimSpace(header))
|
||||
h.Add(k, header)
|
||||
}
|
||||
}
|
||||
return h, nil
|
||||
|
||||
@@ -173,14 +173,14 @@ func (e *RawEntry) Finalize() {
|
||||
}
|
||||
|
||||
func (e *RawEntry) splitPorts() (lp string, pp string, extra string) {
|
||||
portSplit := strings.Split(e.Port, ":")
|
||||
portSplit := strutils.SplitRune(e.Port, ':')
|
||||
if len(portSplit) == 1 {
|
||||
pp = portSplit[0]
|
||||
} else {
|
||||
lp = portSplit[0]
|
||||
pp = portSplit[1]
|
||||
if len(portSplit) > 2 {
|
||||
extra = strings.Join(portSplit[2:], ":")
|
||||
extra = strutils.JoinRune(portSplit[2:], ':')
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -197,7 +197,7 @@ func joinPorts(lp string, pp string, extra string) string {
|
||||
if extra != "" {
|
||||
s = append(s, extra)
|
||||
}
|
||||
return strings.Join(s, ":")
|
||||
return strutils.JoinRune(s, ':')
|
||||
}
|
||||
|
||||
func lowestPort(ports map[string]types.Port) string {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
)
|
||||
|
||||
type StreamPort struct {
|
||||
@@ -14,7 +13,7 @@ type StreamPort struct {
|
||||
var ErrStreamPortTooManyColons = E.New("too many colons")
|
||||
|
||||
func ValidateStreamPort(p string) (StreamPort, error) {
|
||||
split := strings.Split(p, ":")
|
||||
split := strutils.SplitRune(p, ':')
|
||||
|
||||
switch len(split) {
|
||||
case 1:
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
)
|
||||
|
||||
type StreamScheme struct {
|
||||
@@ -14,7 +12,7 @@ type StreamScheme struct {
|
||||
|
||||
func ValidateStreamScheme(s string) (*StreamScheme, error) {
|
||||
ss := &StreamScheme{}
|
||||
parts := strings.Split(s, ":")
|
||||
parts := strutils.SplitRune(s, ':')
|
||||
if len(parts) == 1 {
|
||||
parts = []string{s, s}
|
||||
} else if len(parts) != 2 {
|
||||
@@ -33,7 +31,7 @@ func ValidateStreamScheme(s string) (*StreamScheme, error) {
|
||||
}
|
||||
|
||||
func (s StreamScheme) String() string {
|
||||
return fmt.Sprintf("%s -> %s", s.ListeningScheme, s.ProxyScheme)
|
||||
return string(s.ListeningScheme) + " -> " + string(s.ProxyScheme)
|
||||
}
|
||||
|
||||
// IsCoherent checks if the ListeningScheme and ProxyScheme of the StreamScheme are equal.
|
||||
|
||||
Reference in New Issue
Block a user