...

Source file src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/types.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule

     1  package httprule
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type template struct {
     9  	segments []segment
    10  	verb     string
    11  	template string
    12  }
    13  
    14  type segment interface {
    15  	fmt.Stringer
    16  	compile() (ops []op)
    17  }
    18  
    19  type wildcard struct{}
    20  
    21  type deepWildcard struct{}
    22  
    23  type literal string
    24  
    25  type variable struct {
    26  	path     string
    27  	segments []segment
    28  }
    29  
    30  func (wildcard) String() string {
    31  	return "*"
    32  }
    33  
    34  func (deepWildcard) String() string {
    35  	return "**"
    36  }
    37  
    38  func (l literal) String() string {
    39  	return string(l)
    40  }
    41  
    42  func (v variable) String() string {
    43  	var segs []string
    44  	for _, s := range v.segments {
    45  		segs = append(segs, s.String())
    46  	}
    47  	return fmt.Sprintf("{%s=%s}", v.path, strings.Join(segs, "/"))
    48  }
    49  
    50  func (t template) String() string {
    51  	var segs []string
    52  	for _, s := range t.segments {
    53  		segs = append(segs, s.String())
    54  	}
    55  	str := strings.Join(segs, "/")
    56  	if t.verb != "" {
    57  		str = fmt.Sprintf("%s:%s", str, t.verb)
    58  	}
    59  	return "/" + str
    60  }
    61  

View as plain text