From 1d4beca3367c9f7051a0e02d28dbe359eea509de Mon Sep 17 00:00:00 2001 From: Adam French Date: Wed, 4 Mar 2026 14:21:51 +0000 Subject: [PATCH] Add claude client to store --- backend/go.mod | 3 ++- backend/go.sum | 4 ++++ backend/handlers/store.go | 2 ++ backend/main.go | 14 ++++++++++++-- backend/services/claude.go | 15 +++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 backend/services/claude.go diff --git a/backend/go.mod b/backend/go.mod index 5be142f..7f13ee9 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -7,12 +7,13 @@ require ( github.com/golang-jwt/jwt/v5 v5.3.0 github.com/zmb3/spotify/v2 v2.4.3 golang.org/x/crypto v0.43.0 - golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 + golang.org/x/oauth2 v0.30.0 gorm.io/driver/postgres v1.6.0 gorm.io/gorm v1.31.1 ) require ( + github.com/anthropics/anthropic-sdk-go v1.26.0 // indirect github.com/bytedance/sonic v1.14.0 // indirect github.com/bytedance/sonic/loader v0.3.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect diff --git a/backend/go.sum b/backend/go.sum index 952be2f..cfcba74 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/anthropics/anthropic-sdk-go v1.26.0 h1:oUTzFaUpAevfuELAP1sjL6CQJ9HHAfT7CoSYSac11PY= +github.com/anthropics/anthropic-sdk-go v1.26.0/go.mod h1:qUKmaW+uuPB64iy1l+4kOSvaLqPXnHTTBKH6RVZ7q5Q= github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ= github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA= github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA= @@ -287,6 +289,8 @@ golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 h1:Ati8dO7+U7mxpkPSxBZQEvzHVUYB/MqCklCN8ig5w/o= golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= +golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/backend/handlers/store.go b/backend/handlers/store.go index 9e487fc..9ed6f47 100644 --- a/backend/handlers/store.go +++ b/backend/handlers/store.go @@ -4,6 +4,7 @@ import ( "time" "adam-french.co.uk/backend/services" + "github.com/anthropics/anthropic-sdk-go" "github.com/zmb3/spotify/v2" spotifyauth "github.com/zmb3/spotify/v2/auth" "gorm.io/gorm" @@ -13,6 +14,7 @@ type Store struct { DB *gorm.DB SpotifyAuth *spotifyauth.Authenticator SpotifyClient *spotify.Client + ClaudeClient *anthropic.Client Auth *services.Auth Notes *services.Notes diff --git a/backend/main.go b/backend/main.go index 8e103aa..8deb386 100644 --- a/backend/main.go +++ b/backend/main.go @@ -40,12 +40,18 @@ func main() { log.Fatal(err) } + // SPOTIFY spotifyAuthState := os.Getenv("SPOTIFY_AUTH_STATE") spotifyRedirectURL := os.Getenv("SPOTIFY_REDIRECT_URI") spotifyClientID := os.Getenv("SPOTIFY_CLIENT_ID") spotifyClientSecret := os.Getenv("SPOTIFY_CLIENT_SECRET") spotifyConfig := services.SpotifyConfig{AuthState: spotifyAuthState, RedirectURL: spotifyRedirectURL, ClientID: spotifyClientID, ClientSecret: spotifyClientSecret} - spotifyAuth, client := services.InitSpotifyAuth(&spotifyConfig) + spotifyAuth, spotifyClient := services.InitSpotifyAuth(&spotifyConfig) + + // CLAUDE + claudeAPIKey := os.Getenv("CLAUDE_API_KEY") + claudeConfig := services.ClaudeConfig{APIKey: claudeAPIKey} + claudeClient := services.InitClaude(&claudeConfig) authSecret := os.Getenv("BACKEND_SECRET") domainName := os.Getenv("DOMAIN") @@ -59,7 +65,7 @@ func main() { notesConfig := services.NotesConfig{Dir: notesDir} notes := services.InitNotes(¬esConfig) - store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: client, Auth: auth, Notes: notes} + store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: spotifyClient, ClaudeClient: claudeClient, Auth: auth, Notes: notes} protected := r.Group("/", store.AuthMiddlewear) @@ -67,6 +73,10 @@ func main() { r.GET("/favorites", store.GetFavorites) protected.POST("/favorites", store.CreateFavorite) + // ROWING + r.GET("/rowing", store.GetRowing) + protected.POST("/rowing", store.CreateRowing) + // ACTIVITIES r.GET("/activity", store.GetActivity) protected.POST("/activity", store.CreateActivity) diff --git a/backend/services/claude.go b/backend/services/claude.go new file mode 100644 index 0000000..cb13dcc --- /dev/null +++ b/backend/services/claude.go @@ -0,0 +1,15 @@ +package services + +import ( + "github.com/anthropics/anthropic-sdk-go" + "github.com/anthropics/anthropic-sdk-go/option" +) + +type ClaudeConfig struct { + APIKey string +} + +func InitClaude(config *ClaudeConfig) *anthropic.Client { + client := anthropic.NewClient(option.WithAPIKey(config.APIKey)) + return &client +}