trpc.group/trpc-go/trpc-cmdline@v1.0.9/util/apidocs/info.go (about) 1 // Tencent is pleased to support the open source community by making tRPC available. 2 // 3 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 4 // All rights reserved. 5 // 6 // If you have downloaded a copy of the tRPC source code from Tencent, 7 // please note that tRPC source code is licensed under the Apache 2.0 License, 8 // A copy of the Apache 2.0 License is included in this file. 9 10 package apidocs 11 12 import ( 13 "fmt" 14 "path/filepath" 15 "strings" 16 17 "trpc.group/trpc-go/trpc-cmdline/descriptor" 18 ) 19 20 // InfoStruct defines the structure of the documentation description information contained in the apidocs header. 21 type InfoStruct struct { 22 Title string `json:"title"` // Title of the doc. 23 Description string `json:"description,omitempty"` // Description of the doc. 24 Version string `json:"version,omitempty"` // Version of the doc. 25 } 26 27 // NewInfo inits Info instance. 28 func NewInfo(fd *descriptor.FileDescriptor) (InfoStruct, error) { 29 filePath, err := filepath.Abs(fd.FilePath) 30 if err != nil { 31 return InfoStruct{}, err 32 } 33 _, fileName := filepath.Split(filePath) 34 title := strings.ReplaceAll(fileName, ".proto", "") 35 infoMap := InfoStruct{ 36 Title: title, 37 Description: fmt.Sprintf("The api document of %s", fileName), 38 Version: "2.0", 39 } 40 return infoMap, nil 41 }