Skip to content

Commit

Permalink
forgot to add
Browse files Browse the repository at this point in the history
  • Loading branch information
andro404-MC committed May 13, 2024
1 parent 536da6b commit b77060a
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions data.go
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
}

0 comments on commit b77060a

Please sign in to comment.