1
0
mirror of https://github.com/fumiama/yamaih.git synced 2026-06-27 07:30:23 +08:00

init: lib and cmd

This commit is contained in:
源文雨
2025-03-30 20:37:25 +09:00
parent 7ba5efcc59
commit 7007fd5def
8 changed files with 325 additions and 0 deletions

37
gemini.go Normal file
View File

@@ -0,0 +1,37 @@
package yamaih
import (
"net/http"
"sync"
sql "github.com/FloatTech/sqlite"
)
const api = "https://generativelanguage.googleapis.com"
type Gemini struct {
dbmu sync.Mutex
endpoint string
apiver string // apiver usually v1beta
logdb sql.Sqlite
mux *http.ServeMux
}
func NewGemini(endpoint, logfile, apiver string) *Gemini {
g := &Gemini{
endpoint: endpoint,
apiver: apiver,
logdb: sql.New(logfile),
mux: http.NewServeMux(),
}
err := g.initdb()
if err != nil {
panic(err)
}
g.mux.HandleFunc("/", g.handler)
return g
}
func (g *Gemini) RunBlocking() error {
return http.ListenAndServe(g.endpoint, g.mux)
}