-
Notifications
You must be signed in to change notification settings - Fork 611
feat: refactor apis for existing check and other apis #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5dc137b
fix code style
johzchen 1903243
fix code style
johzchen b8a5f8d
feat support query
johzchen 241d5f9
feat: support query
johzchen 038f673
change: `like` to `equal`
johzchen bc40bb2
fix api status
johzchen 358f53e
feat: upstream existing check
johzchen c122536
feat: refactor api for upstream names
johzchen da70dc3
fix: license
johzchen 17cbcc3
test: add unit test cases
johzchen 9fbf8fa
fix: update bug
johzchen ef1babc
test: add test cases for route
johzchen e1f8f49
fix: unified respond format
johzchen 2747a0f
test: remove test bug
johzchen cda5d48
feat: ssl existing check
johzchen 4ded654
fix bug: auto generate id
johzchen 26af99f
fix: improve consumer
johzchen b3b3c4a
fix: remove key and keys in ssl respond
johzchen 4106036
fix: when list is empty, should respond an empty array
johzchen 848ffbf
fix code style
johzchen d0f1bd6
feat: plugin orchestration
johzchen cb1180e
fix delete bug
johzchen 0a55cf4
fix bug
johzchen 9b61a51
fix: keep the same request params and respond with the old format
johzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| 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. | ||
| */ | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @nic-chen