代码拉取完成,页面将自动刷新
// Licensed 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.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-08-20
package gen_annotation
import (
"fmt"
"regexp"
"strconv"
"strings"
)
var (
RegexAnnotationAddQuotes = regexp.MustCompile(`,([^"]*),`)
RegexAnnotationRemoveCommaSpace = regexp.MustCompile(`\s*,\s*`)
)
type (
// Annotation
// is a type name for @ definition.
Annotation string
AnnotationItem struct {
Annotation Annotation
value string
values []string
}
)
const (
AnnotationAny Annotation = "any"
AnnotationDelete Annotation = "delete"
AnnotationGet Annotation = "get"
AnnotationHead Annotation = "head"
AnnotationOptions Annotation = "options"
AnnotationPatch Annotation = "patch"
AnnotationPost Annotation = "post"
AnnotationPut Annotation = "put"
AnnotationCron Annotation = "cron"
AnnotationCronGloballyUnique Annotation = "crongloballyunique"
AnnotationCronRunOnStartup Annotation = "cronrunonstartup"
AnnotationCronUnique Annotation = "cronunique"
AnnotationMiddleware Annotation = "middleware"
AnnotationName Annotation = "name"
AnnotationRoutePrefix Annotation = "routeprefix"
)
func (o Annotation) String() string {
return string(o)
}
func (o Annotation) ToUpper() string {
return strings.ToUpper(o.String())
}
func NewAnnotationItem(anno Annotation, value string) *AnnotationItem {
return (&AnnotationItem{
Annotation: anno,
value: value,
values: make([]string, 0),
}).init()
}
func (o *AnnotationItem) First() (str string) {
if len(o.values) > 0 {
return o.values[0]
}
return ""
}
func (o *AnnotationItem) FirstBool() bool {
if s := o.First(); s != "" {
if v, err := strconv.ParseBool(s); err == nil {
return v
}
}
return false
}
func (o *AnnotationItem) Values() []string {
return o.values
}
func (o *AnnotationItem) init() *AnnotationItem {
// Remove
// comma space and add end comma.
o.value = "," + RegexAnnotationRemoveCommaSpace.ReplaceAllString(o.value, ",") + ","
// Add
// each part with quotes.
o.value = RegexAnnotationAddQuotes.ReplaceAllStringFunc(o.value, func(s string) string {
if m := RegexAnnotationAddQuotes.FindStringSubmatch(s); len(m) > 0 {
return fmt.Sprintf(`,"%s",`, m[1])
}
return s
})
// Remove start and end comma.
o.value = strings.TrimPrefix(o.value, ",")
o.value = strings.TrimSuffix(o.value, ",")
// Split value as a slice.
for _, s := range strings.Split(o.value, `","`) {
if s = strings.TrimSpace(s); s != "" {
s = strings.TrimPrefix(s, `"`)
s = strings.TrimSuffix(s, `"`)
s = strings.TrimSpace(s)
}
o.values = append(o.values, s)
}
return o
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。