github.com/searKing/golang/go@v1.2.117/net/ice/scheme.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ice
     6  
     7  import (
     8  	"fmt"
     9  	"strings"
    10  )
    11  
    12  // Scheme indicates the type of server used in the ice.URL structure.
    13  type Scheme string
    14  
    15  const (
    16  	// SchemeSTUN indicates the URL represents a STUN server.
    17  	SchemeSTUN Scheme = "stun"
    18  
    19  	// SchemeSTUNS indicates the URL represents a STUNS (secure) server.
    20  	SchemeSTUNS Scheme = "stuns"
    21  
    22  	// SchemeTURN indicates the URL represents a TURN server.
    23  	SchemeTURN Scheme = "turn"
    24  
    25  	// SchemeTURNS indicates the URL represents a TURNS (secure) server.
    26  	SchemeTURNS Scheme = "turns"
    27  )
    28  
    29  func ParseSchemeType(s string) (Scheme, error) {
    30  	scheme := Scheme(strings.ToLower(s))
    31  	switch scheme {
    32  	case SchemeSTUN, SchemeSTUNS, SchemeTURN, SchemeTURNS:
    33  		return scheme, nil
    34  	default:
    35  		return "", fmt.Errorf("malformed scheme %s", s)
    36  	}
    37  }
    38  
    39  func (t Scheme) String() string {
    40  	switch t {
    41  	case SchemeSTUN, SchemeSTUNS, SchemeTURN, SchemeTURNS:
    42  		return string(t)
    43  	default:
    44  		return fmt.Errorf("malformed scheme %s", string(t)).Error()
    45  	}
    46  }