mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
feat: read file and add to prompt
This commit is contained in:
24
reader/file.go
Normal file
24
reader/file.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package reader
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
func FileToPrompt(cmd *string, filePath string) error {
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
reader := bufio.NewReader(f)
|
||||
*cmd = *cmd + "\nFile path: " + filePath + "\n"
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
*cmd = *cmd + "\n" + line
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user