github.com/sanposhiho/openapi2proto@v0.0.0-20230521044535-d1080a134e37/openapi/prototag.go (about)

     1  package openapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  )
     7  
     8  type protoTag int
     9  
    10  func (pt *protoTag) UnmarshalJSON(b []byte) error {
    11  	if b[0] != '"' {
    12  		return json.Unmarshal(b, (*int)(pt))
    13  	}
    14  
    15  	var s string
    16  	if err := json.Unmarshal(b, &s); err != nil {
    17  		return err
    18  	}
    19  
    20  	i, err := strconv.Atoi(s)
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	*pt = protoTag(i)
    26  
    27  	return nil
    28  }