field.go raw

   1  // Copyright 2020 Huawei Technologies Co.,Ltd.
   2  //
   3  // Licensed to the Apache Software Foundation (ASF) under one
   4  // or more contributor license agreements.  See the NOTICE file
   5  // distributed with this work for additional information
   6  // regarding copyright ownership.  The ASF licenses this file
   7  // to you under the Apache License, Version 2.0 (the
   8  // "License"); you may not use this file except in compliance
   9  // with the License.  You may obtain a copy of the License at
  10  //
  11  //     http://www.apache.org/licenses/LICENSE-2.0
  12  //
  13  // Unless required by applicable law or agreed to in writing,
  14  // software distributed under the License is distributed on an
  15  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16  // KIND, either express or implied.  See the License for the
  17  // specific language governing permissions and limitations
  18  // under the License.
  19  
  20  package def
  21  
  22  type LocationType int32
  23  
  24  const (
  25  	Header LocationType = 1 << iota
  26  	Path
  27  	Query
  28  	Body
  29  	Form
  30  	Cname
  31  )
  32  
  33  type FieldDef struct {
  34  	LocationType LocationType
  35  	Name         string
  36  	JsonTag      string
  37  	KindName     string
  38  }
  39  
  40  func NewFieldDef() *FieldDef {
  41  	return &FieldDef{}
  42  }
  43  
  44  func (field *FieldDef) WithLocationType(locationType LocationType) *FieldDef {
  45  	field.LocationType = locationType
  46  	return field
  47  }
  48  
  49  func (field *FieldDef) WithName(name string) *FieldDef {
  50  	field.Name = name
  51  	return field
  52  }
  53  
  54  func (field *FieldDef) WithJsonTag(tag string) *FieldDef {
  55  	field.JsonTag = tag
  56  	return field
  57  }
  58  
  59  func (field *FieldDef) WithKindName(kindName string) *FieldDef {
  60  	field.KindName = kindName
  61  	return field
  62  }
  63