gospt/main.go

41 lines
696 B
Go
Raw Normal View History

2023-01-06 23:40:39 -08:00
package main
import (
"context"
"fmt"
2023-01-07 16:03:43 -08:00
"log"
2023-01-06 23:40:39 -08:00
"os"
"path/filepath"
2023-01-07 21:34:31 -08:00
"gospt/internal/api"
2023-01-07 21:22:54 -08:00
"gospt/internal/auth"
"gospt/internal/config"
2023-01-07 21:26:06 -08:00
"gospt/internal/gctx"
2023-01-06 23:40:39 -08:00
)
func init() {
2023-01-08 21:08:51 -08:00
configPath, _ := os.UserConfigDir()
configDir := filepath.Join(configPath, "gospt")
2023-01-06 23:40:39 -08:00
config.LoadConfig(configDir)
}
func main() {
var err error
2023-01-07 16:03:43 -08:00
log.New(os.Stdout, "LOG:", 0)
2023-01-07 21:26:06 -08:00
ctx := gctx.NewContext(context.Background())
2023-01-07 21:22:54 -08:00
client, err := auth.GetClient(ctx)
2023-01-06 23:40:39 -08:00
if err != nil {
2023-01-08 21:08:51 -08:00
fmt.Println(err.Error())
return
2023-01-06 23:40:39 -08:00
}
2023-01-07 23:57:33 -08:00
currentUser, err := client.CurrentUser(ctx)
if err != nil {
panic(err.Error())
}
ctx.UserId = currentUser.ID
2023-01-07 21:34:31 -08:00
err = api.Run(ctx, client, os.Args[1:])
2023-01-06 23:40:39 -08:00
if err != nil {
fmt.Println(err)
}
}