github.com/gogf/gf/v2@v2.7.4/net/goai/goai_external_docs.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package goai
     8  
     9  import (
    10  	"github.com/gogf/gf/v2/internal/json"
    11  	"github.com/gogf/gf/v2/text/gstr"
    12  	"github.com/gogf/gf/v2/util/gconv"
    13  )
    14  
    15  // ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.
    16  type ExternalDocs struct {
    17  	URL         string `json:"url,omitempty"`
    18  	Description string `json:"description,omitempty"`
    19  }
    20  
    21  func (ed *ExternalDocs) UnmarshalValue(value interface{}) error {
    22  	var valueBytes = gconv.Bytes(value)
    23  	if json.Valid(valueBytes) {
    24  		return json.UnmarshalUseNumber(valueBytes, ed)
    25  	}
    26  	var (
    27  		valueString = string(valueBytes)
    28  		valueArray  = gstr.Split(valueString, "|")
    29  	)
    30  	ed.URL = valueArray[0]
    31  	if len(valueArray) > 1 {
    32  		ed.Description = valueArray[1]
    33  	}
    34  	return nil
    35  }