github.com/btccom/go-micro/v2@v2.9.3/api/router/util/types.go (about)

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