github.com/yandex/pandora@v0.5.32/components/providers/http/decoders/uripost/decoder.go (about)

     1  package uripost
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  var ErrWrongSize = fmt.Errorf("wrong ammo bodySize format: should be int, in 'bodySize uri [tag]'")
    10  var ErrAmmoFormat = fmt.Errorf("wrong ammo format: should be like 'bodySize uri [tag]'")
    11  
    12  func DecodeURI(uriString string) (bodySize int, uri string, tag string, err error) {
    13  	parts := strings.Split(uriString, " ")
    14  	if len(parts) < 2 {
    15  		err = ErrAmmoFormat
    16  	} else {
    17  		bodySize, err = strconv.Atoi(parts[0])
    18  		if err != nil {
    19  			err = ErrWrongSize
    20  			return
    21  		}
    22  		uri = parts[1]
    23  		if len(parts) > 2 {
    24  			tag = strings.Join(parts[2:], " ")
    25  		}
    26  	}
    27  
    28  	return
    29  }