...

Source file src/github.com/emicklei/go-restful/v3/route_reader.go

Documentation: github.com/emicklei/go-restful/v3

     1  package restful
     2  
     3  // Copyright 2021 Ernest Micklei. All rights reserved.
     4  // Use of this source code is governed by a license
     5  // that can be found in the LICENSE file.
     6  
     7  type RouteReader interface {
     8  	Method() string
     9  	Consumes() []string
    10  	Path() string
    11  	Doc() string
    12  	Notes() string
    13  	Operation() string
    14  	ParameterDocs() []*Parameter
    15  	// Returns a copy
    16  	Metadata() map[string]interface{}
    17  	Deprecated() bool
    18  }
    19  
    20  type routeAccessor struct {
    21  	route *Route
    22  }
    23  
    24  func (r routeAccessor) Method() string {
    25  	return r.route.Method
    26  }
    27  func (r routeAccessor) Consumes() []string {
    28  	return r.route.Consumes[:]
    29  }
    30  func (r routeAccessor) Path() string {
    31  	return r.route.Path
    32  }
    33  func (r routeAccessor) Doc() string {
    34  	return r.route.Doc
    35  }
    36  func (r routeAccessor) Notes() string {
    37  	return r.route.Notes
    38  }
    39  func (r routeAccessor) Operation() string {
    40  	return r.route.Operation
    41  }
    42  func (r routeAccessor) ParameterDocs() []*Parameter {
    43  	return r.route.ParameterDocs[:]
    44  }
    45  
    46  // Returns a copy
    47  func (r routeAccessor) Metadata() map[string]interface{} {
    48  	return copyMap(r.route.Metadata)
    49  }
    50  func (r routeAccessor) Deprecated() bool {
    51  	return r.route.Deprecated
    52  }
    53  
    54  // https://stackoverflow.com/questions/23057785/how-to-copy-a-map
    55  func copyMap(m map[string]interface{}) map[string]interface{} {
    56  	cp := make(map[string]interface{})
    57  	for k, v := range m {
    58  		vm, ok := v.(map[string]interface{})
    59  		if ok {
    60  			cp[k] = copyMap(vm)
    61  		} else {
    62  			cp[k] = v
    63  		}
    64  	}
    65  	return cp
    66  }
    67  

View as plain text