github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/thrift/annotation/register.go (about) 1 /** 2 * Copyright 2023 CloudWeGo Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package annotation 18 19 import ( 20 "fmt" 21 22 "github.com/cloudwego/dynamicgo/meta" 23 "github.com/cloudwego/dynamicgo/thrift" 24 ) 25 26 func init() { 27 // HttpMapping 28 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIQuery)), "api.query") 29 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIPath)), "api.path") 30 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIHeader)), "api.header") 31 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APICookie)), "api.cookie") 32 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIBody)), "api.body") 33 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIHTTPCode)), "api.http_code") 34 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIRawBody)), "api.raw_body") 35 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIPostForm)), "api.form") 36 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APIRawUri)), "api.raw_uri") 37 thrift.RegisterAnnotation(newHttpMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindHttpMappping, thrift.AnnoScopeField, APINoBodyStruct)), "api.no_body_struct") 38 39 // OptionMaker 40 41 // ValueMapping 42 thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, JSConv)), "api.js_conv") 43 44 // KeyMapping 45 46 // AnnotationMapper 47 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, goTagMapper{}, "go.tag") 48 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, apiBodyMapper{}, "api.body") 49 // make raw.body not failed, expected caller to implement this anno 50 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, apiBodyMapper{}, "raw.body") 51 thrift.RegisterAnnotationMapper(thrift.AnnoScopeService, nameCaseMapper{}, NameCaseKeys...) 52 thrift.RegisterAnnotationMapper(thrift.AnnoScopeFunction, nameCaseMapper{}, NameCaseKeys...) 53 thrift.RegisterAnnotationMapper(thrift.AnnoScopeStruct, nameCaseMapper{}, NameCaseKeys...) 54 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, nameCaseMapper{}, NameCaseKeys...) 55 } 56 57 // This is only used for internal specifications. 58 // DO NOT USE IT if you don't know related annotations 59 func InitAGWAnnos() { 60 thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, JSConv)), "agw.js_conv") 61 thrift.RegisterAnnotation(newValueMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindValueMapping, thrift.AnnoScopeField, BodyDynamic)), "agw.body_dynamic") 62 thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, APIKey)), "agw.key", APIKeyName) 63 // thrift.RegisterAnnotation(newKeyMappingAnnotation(thrift.MakeAnnoID(thrift.AnnoKindKeyMapping, thrift.AnnoScopeField, NameCase)), "agw.to_snake", "janus.to_snake", "agw.to_lower_camel_case", "janus.to_lower_camel_case") 64 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, sourceMapper{}, "janus.source", "agw.source") 65 thrift.RegisterAnnotationMapper(thrift.AnnoScopeField, targetMapper{}, "agw.target", "janus.target") 66 } 67 68 //go:noline 69 func errNotFound(key string, scope string) error { 70 return meta.NewError(meta.ErrNotFound, fmt.Sprintf("not fould %s in %s", key, scope), nil) 71 } 72 73 //go:noline 74 func errNotImplemented(msg string) error { 75 return meta.NewError(meta.ErrUnsupportedType, msg, nil) 76 } 77 78