github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/get_file.go (about) 1 /* 2 Golang To Github Markdown Utility: gotomd 3 Copyright (C) 2023, 2024 Leslie Dancsecs 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 package main 20 21 import ( 22 "os" 23 ) 24 25 const catCmd = "cat " 26 27 func getGoFile(cmd string) (string, error) { 28 var ( 29 fData []byte 30 res string 31 ) 32 33 dir, fName, err := parseCmds(cmd) 34 for i, mi := 0, len(dir); i < mi && err == nil; i++ { 35 fPath := dir[i] + string(os.PathSeparator) + fName[i] 36 fData, err = os.ReadFile(fPath) //nolint:gosec // Ok. 37 38 if err == nil { 39 if res != "" { 40 res += "\n\n" 41 } 42 43 res += "" + 44 markBashCode(catCmd+fPath) + "\n\n" + 45 markGoCode(string(fData)) 46 } 47 } 48 49 if err == nil { 50 return res, nil 51 } 52 53 return "", err //nolint:wrapcheck // Caller will wrap error. 54 }