-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (45 loc) · 944 Bytes
/
main.go
File metadata and controls
55 lines (45 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"log"
"os"
"strings"
"time"
"github.com/abtsousa/hook/internal/gemini"
"github.com/abtsousa/hook/safe_error"
)
// Path to the API key.
const API_PATH = ".api-key"
var API_KEY string
func main() {
// Check parameters
params := strings.Join(os.Args[1:], " ")
if len(params) == 0 {
log.Fatal("You must provide a query.")
}
// Get API key
if os.Getenv("GEMINI_API_KEY") != "" {
API_KEY = os.Getenv("GEMINI_API_KEY")
} else {
api_key, err := os.ReadFile(API_PATH)
if err != nil {
log.Fatalf("Please save your API key in the file %s", API_PATH)
}
API_KEY = strings.TrimSpace(string(api_key))
}
safe_error.API_KEY = API_KEY
gemini.API_KEY = API_KEY
// Run
run(params)
}
func run(params string) {
client, err := gemini.NewClient(time.Second * 45)
if err != nil {
log.Fatal(err)
}
reply, err := client.Query(params)
if err != nil {
log.Fatal(err)
}
fmt.Println(reply)
}