-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
536da6b
commit b77060a
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
type configSTR struct { | ||
Apikey string | ||
} | ||
|
||
var ( | ||
config configSTR | ||
prompts = map[string]string{ | ||
"Ask": "give the shortest respond MAX 50 words", | ||
"Correct": "Correct the grammar of the following sentence without any extra text just pure correction", | ||
} | ||
) | ||
|
||
func load(c *configSTR) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
log.Println("Error getting user home directory:", err) | ||
os.Exit(3) | ||
} | ||
|
||
fullPath := homeDir + configPath | ||
if _, err := os.Stat(fullPath); os.IsNotExist(err) { | ||
c.Apikey = "GEMINI-PRO" | ||
return | ||
} | ||
|
||
_, err = toml.DecodeFile(fullPath, &c) | ||
if err != nil { | ||
log.Println("Error:", err) | ||
return | ||
} | ||
|
||
return | ||
} | ||
|
||
func save(c *configSTR) { | ||
fileString := fmt.Sprintf("apikey = \"%s\"", c.Apikey) | ||
|
||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
log.Println("Error getting user home directory:", err) | ||
os.Exit(3) | ||
} | ||
|
||
fullPath := homeDir + configPath | ||
|
||
dirPath := filepath.Dir(fullPath) | ||
err = os.MkdirAll(dirPath, os.ModePerm) | ||
if err != nil { | ||
fmt.Println("Error creating directory:", err) | ||
return | ||
} | ||
|
||
err = os.WriteFile(fullPath, []byte(fileString), 0o644) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
return | ||
} | ||
return | ||
} |