Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions api/errno/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

type Message struct {
Code string
Msg string
Status int `json:"-"`
Msg string `json:"message"`
Status int `json:"-"`
}

var (
Expand Down Expand Up @@ -128,25 +128,25 @@ func New(m Message, args ...interface{}) *ManagerError {

func (e *ManagerError) Response() map[string]interface{} {
return map[string]interface{}{
"code": e.Code,
"msg": e.Msg,
"code": e.Code,
"message": e.Msg,
}
}

func (e *ManagerError) ItemResponse(data interface{}) map[string]interface{} {
return map[string]interface{}{
"code": e.Code,
"msg": e.Msg,
"data": data,
"code": e.Code,
"message": e.Msg,
"data": data,
}
}

func (e *ManagerError) ListResponse(count, list interface{}) map[string]interface{} {
return map[string]interface{}{
"code": e.Code,
"msg": e.Msg,
"count": count,
"list": list,
"code": e.Code,
"message": e.Msg,
"count": count,
"list": list,
}
}

Expand Down
32 changes: 25 additions & 7 deletions api/internal/core/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Route struct {
RemoteAddrs []string `json:"remote_addrs,omitempty"`
Vars string `json:"vars,omitempty"`
FilterFunc string `json:"filter_func,omitempty"`
Script string `json:"script,omitempty"`
Script interface{} `json:"script,omitempty"`
Plugins interface{} `json:"plugins,omitempty"`
Upstream Upstream `json:"upstream,omitempty"`
ServiceID string `json:"service_id,omitempty"`
Expand Down Expand Up @@ -113,6 +113,7 @@ type HealthChecker struct {
}

type Upstream struct {
BaseInfo
Nodes []Node `json:"nodes,omitempty"`
Retries int `json:"retries,omitempty"`
Timeout Timeout `json:"timeout,omitempty"`
Expand All @@ -127,38 +128,55 @@ type Upstream struct {
Name string `json:"name,omitempty"`
Desc string `json:"desc,omitempty"`
ServiceName string `json:"service_name,omitempty"`
ID string `json:"id,omitempty"`
}

type UpstreamNameResponse struct {
ID string `json:"id"`
Name string `json:"name"`
}

func (upstream *Upstream) Parse2NameResponse() (*UpstreamNameResponse, error) {
nameResp := &UpstreamNameResponse{
ID: upstream.ID,
Name: upstream.Name,
}
return nameResp, nil
}

// --- structures for upstream end ---

type Consumer struct {
ID string `json:"id"`
BaseInfo
Username string `json:"username"`
Desc string `json:"desc,omitempty"`
Plugins interface{} `json:"plugins,omitempty"`
}

type SSL struct {
ID string `json:"id"`
BaseInfo
Cert string `json:"cert"`
Key string `json:"key"`
Key string `json:"key,omitempty"`
Sni string `json:"sni"`
Snis []string `json:"snis"`
Certs []string `json:"certs"`
Keys []string `json:"keys"`
Keys []string `json:"keys,omitempty"`
ExpTime int64 `json:"exptime"`
Status int `json:"status"`
ValidityStart int64 `json:"validity_start"`
ValidityEnd int64 `json:"validity_end"`
}

type Service struct {
ID string `json:"id"`
BaseInfo
Name string `json:"name,omitempty"`
Desc string `json:"desc,omitempty"`
Upstream Upstream `json:"upstream,omitempty"`
UpstreamID string `json:"upstream_id,omitempty"`
Plugins interface{} `json:"plugins,omitempty"`
Script string `json:"script,omitempty"`
}

type Script struct {
ID string `json:"id"`
Script interface{} `json:"script,omitempty"`
}
153 changes: 153 additions & 0 deletions api/internal/core/entity/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate header

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @nic-chen


package entity

import "strings"

type PropertyName string

const (
IdProperty = "id"
NameProperty = "name"
SniProperty = "sni"
SnisProperty = "snis"
CreateTimeProperty = "create_time"
UpdateTimeProperty = "update_time"
)

type ComparableValue interface {
Compare(ComparableValue) int
Contains(ComparableValue) bool
}

type ComparingString string

func (comparing ComparingString) Compare(compared ComparableValue) int {
other := compared.(ComparingString)
return strings.Compare(string(comparing), string(other))
}

func (comparing ComparingString) Contains(compared ComparableValue) bool {
other := compared.(ComparingString)
return strings.Contains(string(comparing), string(other))
}

type ComparingStringArray []string

func (comparing ComparingStringArray) Compare(compared ComparableValue) int {
other := compared.(ComparingString)
res := -1
for _, str := range comparing {
result := strings.Compare(str, string(other))
if result == 0 {
res = 0
break
}
}
return res
}

func (comparing ComparingStringArray) Contains(compared ComparableValue) bool {
other := compared.(ComparingString)
res := false
for _, str := range comparing {
if strings.Contains(str, string(other)) {
res = true
break
}
}
return res
}

type ComparingInt int64

func int64Compare(a, b int64) int {
if a > b {
return 1
} else if a == b {
return 0
}
return -1
}

func (comparing ComparingInt) Compare(compared ComparableValue) int {
other := compared.(ComparingInt)
return int64Compare(int64(comparing), int64(other))
}

func (comparing ComparingInt) Contains(compared ComparableValue) bool {
return comparing.Compare(compared) == 0
}

func (info BaseInfo) GetProperty(name PropertyName) ComparableValue {
switch name {
case IdProperty:
return ComparingString(info.ID)
case CreateTimeProperty:
return ComparingInt(info.CreateTime)
case UpdateTimeProperty:
return ComparingInt(info.UpdateTime)
default:
return nil
}
}

func (route Route) GetProperty(name PropertyName) ComparableValue {
switch name {
case NameProperty:
return ComparingString(route.Name)
default:
return nil
}
}

func (upstream Upstream) GetProperty(name PropertyName) ComparableValue {
switch name {
case NameProperty:
return ComparingString(upstream.Name)
default:
return nil
}
}

func (ssl SSL) GetProperty(name PropertyName) ComparableValue {
switch name {
case SniProperty:
return ComparingString(ssl.Sni)
case SnisProperty:
return ComparingStringArray(ssl.Snis)
default:
return nil
}
}
Loading