diff --git a/cli/cli.go b/cli/cli.go index eda20e2e..02ab9a89 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,7 +2,7 @@ package cli import ( "fmt" - "github.com/danielmiessler/fabric/converter" + "github.com/danielmiessler/fabric/plugins/tools/converter" "github.com/danielmiessler/fabric/restapi" "os" "path/filepath" diff --git a/core/chatter.go b/core/chatter.go index a9dcf330..db6ef96e 100644 --- a/core/chatter.go +++ b/core/chatter.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/danielmiessler/fabric/common" "github.com/danielmiessler/fabric/db" - "github.com/danielmiessler/fabric/vendors" + "github.com/danielmiessler/fabric/plugins/ai" goopenai "github.com/sashabaranov/go-openai" "strings" ) @@ -17,7 +17,7 @@ type Chatter struct { DryRun bool model string - vendor vendors.Vendor + vendor ai.Vendor } func (o *Chatter) Send(request *common.ChatRequest, opts *common.ChatOptions) (session *db.Session, err error) { diff --git a/core/fabric.go b/core/fabric.go index 7e3f87a1..426f6c15 100644 --- a/core/fabric.go +++ b/core/fabric.go @@ -6,18 +6,18 @@ import ( "github.com/atotto/clipboard" "github.com/danielmiessler/fabric/common" "github.com/danielmiessler/fabric/db" - "github.com/danielmiessler/fabric/jina" - "github.com/danielmiessler/fabric/vendors/anthropic" - "github.com/danielmiessler/fabric/vendors/azure" - "github.com/danielmiessler/fabric/vendors/dryrun" - "github.com/danielmiessler/fabric/vendors/gemini" - "github.com/danielmiessler/fabric/vendors/groq" - "github.com/danielmiessler/fabric/vendors/mistral" - "github.com/danielmiessler/fabric/vendors/ollama" - "github.com/danielmiessler/fabric/vendors/openai" - "github.com/danielmiessler/fabric/vendors/openrouter" - "github.com/danielmiessler/fabric/vendors/siliconcloud" - "github.com/danielmiessler/fabric/youtube" + "github.com/danielmiessler/fabric/plugins/ai/anthropic" + "github.com/danielmiessler/fabric/plugins/ai/azure" + "github.com/danielmiessler/fabric/plugins/ai/dryrun" + "github.com/danielmiessler/fabric/plugins/ai/gemini" + "github.com/danielmiessler/fabric/plugins/ai/groq" + "github.com/danielmiessler/fabric/plugins/ai/mistral" + "github.com/danielmiessler/fabric/plugins/ai/ollama" + "github.com/danielmiessler/fabric/plugins/ai/openai" + "github.com/danielmiessler/fabric/plugins/ai/openrouter" + "github.com/danielmiessler/fabric/plugins/ai/siliconcloud" + "github.com/danielmiessler/fabric/plugins/tools/jina" + "github.com/danielmiessler/fabric/plugins/tools/youtube" "github.com/pkg/errors" "os" "strconv" diff --git a/core/vendors.go b/core/vendors.go index 48a8c007..60f5e5b3 100644 --- a/core/vendors.go +++ b/core/vendors.go @@ -3,23 +3,22 @@ package core import ( "context" "fmt" + "github.com/danielmiessler/fabric/plugins/ai" "sync" - - "github.com/danielmiessler/fabric/vendors" ) func NewVendorsManager() *VendorsManager { return &VendorsManager{ - Vendors: map[string]vendors.Vendor{}, + Vendors: map[string]ai.Vendor{}, } } type VendorsManager struct { - Vendors map[string]vendors.Vendor + Vendors map[string]ai.Vendor Models *VendorsModels } -func (o *VendorsManager) AddVendors(vendors ...vendors.Vendor) { +func (o *VendorsManager) AddVendors(vendors ...ai.Vendor) { for _, vendor := range vendors { o.Vendors[vendor.GetName()] = vendor } @@ -36,7 +35,7 @@ func (o *VendorsManager) HasVendors() bool { return len(o.Vendors) > 0 } -func (o *VendorsManager) FindByName(name string) vendors.Vendor { +func (o *VendorsManager) FindByName(name string) ai.Vendor { return o.Vendors[name] } @@ -72,7 +71,7 @@ func (o *VendorsManager) readModels() { } func (o *VendorsManager) fetchVendorModels( - ctx context.Context, wg *sync.WaitGroup, vendor vendors.Vendor, resultsChan chan<- modelResult) { + ctx context.Context, wg *sync.WaitGroup, vendor ai.Vendor, resultsChan chan<- modelResult) { defer wg.Done() @@ -86,8 +85,8 @@ func (o *VendorsManager) fetchVendorModels( } } -func (o *VendorsManager) Setup() (ret map[string]vendors.Vendor, err error) { - ret = map[string]vendors.Vendor{} +func (o *VendorsManager) Setup() (ret map[string]ai.Vendor, err error) { + ret = map[string]ai.Vendor{} for _, vendor := range o.Vendors { fmt.Println() if vendorErr := vendor.Setup(); vendorErr == nil { diff --git a/go.mod b/go.mod index 769f51f8..5d002d87 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,12 @@ go 1.22.5 require ( github.com/anaskhan96/soup v1.2.5 github.com/atotto/clipboard v0.1.4 + github.com/gin-gonic/gin v1.10.0 github.com/go-git/go-git/v5 v5.12.0 github.com/go-shiori/go-readability v0.0.0-20240923125239-59a7bd165825 github.com/google/generative-ai-go v0.18.0 github.com/jessevdk/go-flags v1.6.1 github.com/joho/godotenv v1.5.1 - github.com/labstack/echo/v4 v4.12.0 github.com/liushuangls/go-anthropic/v2 v2.8.0 github.com/ollama/ollama v0.3.11 github.com/otiai10/copy v1.14.0 @@ -34,34 +34,47 @@ require ( github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudflare/circl v1.4.0 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect github.com/cyphar/filepath-securejoin v0.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/go-shiori/dom v0.0.0-20230515143342-73569d674e1c // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f // indirect - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/labstack/gommon v0.4.2 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/skeema/knownhosts v1.3.0 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.2.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0 // indirect @@ -69,6 +82,7 @@ require ( go.opentelemetry.io/otel v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/trace v1.30.0 // indirect + golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect diff --git a/go.sum b/go.sum index d31136fe..6420f3a7 100644 --- a/go.sum +++ b/go.sum @@ -32,11 +32,19 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.4.0 h1:BV7h5MgrktNzytKmWjpOtdYrf0lkkbF8YMlBGPhJQrY= github.com/cloudflare/circl v1.4.0/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cyphar/filepath-securejoin v0.3.2 h1:QhZu5AxQ+o1XZH0Ye05YzvJ0kAdK6VQc0z9NNMek7gc= github.com/cyphar/filepath-securejoin v0.3.2/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= @@ -53,6 +61,12 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= @@ -68,14 +82,22 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-shiori/dom v0.0.0-20230515143342-73569d674e1c h1:wpkoddUomPfHiOziHZixGO5ZBS73cKqVzZipfrLmO1w= github.com/go-shiori/dom v0.0.0-20230515143342-73569d674e1c/go.mod h1:oVDCh3qjJMLVUSILBRwrm+Bc6RNXGZYtoh9xdvf1ffM= github.com/go-shiori/go-readability v0.0.0-20240923125239-59a7bd165825 h1:CpSi7xiWqGaAqVn/2MsbRoDmPwXMvvQUu3hLjX1QrOM= github.com/go-shiori/go-readability v0.0.0-20240923125239-59a7bd165825/go.mod h1:YWa00ashoPZMAOElrSn4E1cJErhDVU6PWAll4Hxzn+w= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs= github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -102,6 +124,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -117,8 +140,14 @@ github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bB github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -126,18 +155,18 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= -github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= -github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= -github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/liushuangls/go-anthropic/v2 v2.8.0 h1:0zH2jDNycbrlszxnLrG+Gx8vVT0yJAPWU4s3ZTkWzgI= github.com/liushuangls/go-anthropic/v2 v2.8.0/go.mod h1:8BKv/fkeTaL5R9R9bGkaknYBueyw2WxY20o7bImbOek= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/ollama/ollama v0.3.11 h1:Fs1B5WjXYUvr5bkMZZpUJfiqIAxrymujRidFABwMeV8= github.com/ollama/ollama v0.3.11/go.mod h1:YrWoNkFnPOYsnDvsf/Ztb1wxU9/IXrNsQHqcxbY2r94= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= @@ -146,6 +175,8 @@ github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -169,19 +200,22 @@ github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= -github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -197,6 +231,9 @@ go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4Q go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -250,7 +287,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -330,3 +366,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/vendors/anthropic/anthropic.go b/plugins/ai/anthropic/anthropic.go similarity index 100% rename from vendors/anthropic/anthropic.go rename to plugins/ai/anthropic/anthropic.go diff --git a/vendors/azure/azure.go b/plugins/ai/azure/azure.go similarity index 94% rename from vendors/azure/azure.go rename to plugins/ai/azure/azure.go index a336a411..0c733960 100644 --- a/vendors/azure/azure.go +++ b/plugins/ai/azure/azure.go @@ -1,10 +1,10 @@ package azure import ( + "github.com/danielmiessler/fabric/plugins/ai/openai" "strings" "github.com/danielmiessler/fabric/common" - "github.com/danielmiessler/fabric/vendors/openai" goopenai "github.com/sashabaranov/go-openai" ) diff --git a/vendors/dryrun/dryrun.go b/plugins/ai/dryrun/dryrun.go similarity index 100% rename from vendors/dryrun/dryrun.go rename to plugins/ai/dryrun/dryrun.go diff --git a/vendors/gemini/gemini.go b/plugins/ai/gemini/gemini.go similarity index 100% rename from vendors/gemini/gemini.go rename to plugins/ai/gemini/gemini.go diff --git a/vendors/groq/groq.go b/plugins/ai/groq/groq.go similarity index 79% rename from vendors/groq/groq.go rename to plugins/ai/groq/groq.go index 4d5722cb..b2805cbc 100644 --- a/vendors/groq/groq.go +++ b/plugins/ai/groq/groq.go @@ -1,7 +1,7 @@ package groq import ( - "github.com/danielmiessler/fabric/vendors/openai" + "github.com/danielmiessler/fabric/plugins/ai/openai" ) func NewClient() (ret *Client) { diff --git a/vendors/mistral/mistral.go b/plugins/ai/mistral/mistral.go similarity index 79% rename from vendors/mistral/mistral.go rename to plugins/ai/mistral/mistral.go index 551881a8..c605e83d 100644 --- a/vendors/mistral/mistral.go +++ b/plugins/ai/mistral/mistral.go @@ -1,7 +1,7 @@ package mistral import ( - "github.com/danielmiessler/fabric/vendors/openai" + "github.com/danielmiessler/fabric/plugins/ai/openai" ) func NewClient() (ret *Client) { diff --git a/vendors/ollama/ollama.go b/plugins/ai/ollama/ollama.go similarity index 100% rename from vendors/ollama/ollama.go rename to plugins/ai/ollama/ollama.go diff --git a/vendors/openai/openai.go b/plugins/ai/openai/openai.go similarity index 100% rename from vendors/openai/openai.go rename to plugins/ai/openai/openai.go diff --git a/vendors/openai/openai_test.go b/plugins/ai/openai/openai_test.go similarity index 100% rename from vendors/openai/openai_test.go rename to plugins/ai/openai/openai_test.go diff --git a/vendors/openrouter/openrouter.go b/plugins/ai/openrouter/openrouter.go similarity index 80% rename from vendors/openrouter/openrouter.go rename to plugins/ai/openrouter/openrouter.go index 2c653cda..e2859d5a 100644 --- a/vendors/openrouter/openrouter.go +++ b/plugins/ai/openrouter/openrouter.go @@ -1,7 +1,7 @@ package openrouter import ( - "github.com/danielmiessler/fabric/vendors/openai" + "github.com/danielmiessler/fabric/plugins/ai/openai" ) func NewClient() (ret *Client) { diff --git a/vendors/siliconcloud/siliconcloud.go b/plugins/ai/siliconcloud/siliconcloud.go similarity index 80% rename from vendors/siliconcloud/siliconcloud.go rename to plugins/ai/siliconcloud/siliconcloud.go index 754a28ae..93fe8d9b 100644 --- a/vendors/siliconcloud/siliconcloud.go +++ b/plugins/ai/siliconcloud/siliconcloud.go @@ -1,7 +1,7 @@ package siliconcloud import ( - "github.com/danielmiessler/fabric/vendors/openai" + "github.com/danielmiessler/fabric/plugins/ai/openai" ) func NewClient() (ret *Client) { diff --git a/vendors/vendor.go b/plugins/ai/vendor.go similarity index 96% rename from vendors/vendor.go rename to plugins/ai/vendor.go index 156f496b..ea8b5889 100644 --- a/vendors/vendor.go +++ b/plugins/ai/vendor.go @@ -1,4 +1,4 @@ -package vendors +package ai import ( "bytes" diff --git a/converter/html_readability.go b/plugins/tools/converter/html_readability.go similarity index 100% rename from converter/html_readability.go rename to plugins/tools/converter/html_readability.go diff --git a/converter/html_readability_test.go b/plugins/tools/converter/html_readability_test.go similarity index 100% rename from converter/html_readability_test.go rename to plugins/tools/converter/html_readability_test.go diff --git a/jina/jina.go b/plugins/tools/jina/jina.go similarity index 100% rename from jina/jina.go rename to plugins/tools/jina/jina.go diff --git a/to_pdf/to_pdf.go b/plugins/tools/to_pdf/to_pdf.go similarity index 100% rename from to_pdf/to_pdf.go rename to plugins/tools/to_pdf/to_pdf.go diff --git a/youtube/youtube.go b/plugins/tools/youtube/youtube.go similarity index 100% rename from youtube/youtube.go rename to plugins/tools/youtube/youtube.go diff --git a/restapi/contexts.go b/restapi/contexts.go index 6f42f3f2..168e4154 100644 --- a/restapi/contexts.go +++ b/restapi/contexts.go @@ -2,7 +2,7 @@ package restapi import ( "github.com/danielmiessler/fabric/db" - "github.com/labstack/echo/v4" + "github.com/gin-gonic/gin" ) // ContextsHandler defines the handler for contexts-related operations @@ -12,8 +12,8 @@ type ContextsHandler struct { } // NewContextsHandler creates a new ContextsHandler -func NewContextsHandler(e *echo.Echo, contexts *db.ContextsEntity) (ret *ContextsHandler) { +func NewContextsHandler(r *gin.Engine, contexts *db.ContextsEntity) (ret *ContextsHandler) { ret = &ContextsHandler{ - StorageHandler: NewStorageHandler[db.Context](e, "contexts", contexts), contexts: contexts} + StorageHandler: NewStorageHandler[db.Context](r, "contexts", contexts), contexts: contexts} return } diff --git a/restapi/patterns.go b/restapi/patterns.go index ec92b776..3e3a5fb7 100644 --- a/restapi/patterns.go +++ b/restapi/patterns.go @@ -2,7 +2,7 @@ package restapi import ( "github.com/danielmiessler/fabric/db" - "github.com/labstack/echo/v4" + "github.com/gin-gonic/gin" "net/http" ) @@ -13,20 +13,21 @@ type PatternsHandler struct { } // NewPatternsHandler creates a new PatternsHandler -func NewPatternsHandler(e *echo.Echo, patterns *db.PatternsEntity) (ret *PatternsHandler) { +func NewPatternsHandler(r *gin.Engine, patterns *db.PatternsEntity) (ret *PatternsHandler) { ret = &PatternsHandler{ - StorageHandler: NewStorageHandler[db.Pattern](e, "patterns", patterns), patterns: patterns} - e.GET("/patterns/:name", ret.GetPattern) + StorageHandler: NewStorageHandler[db.Pattern](r, "patterns", patterns), patterns: patterns} + r.GET("/patterns/:name", ret.GetPattern) return } // GetPattern handles the GET /patterns/:name route -func (h *PatternsHandler) GetPattern(c echo.Context) error { +func (h *PatternsHandler) GetPattern(c *gin.Context) { name := c.Param("name") variables := make(map[string]string) // Assuming variables are passed somehow pattern, err := h.patterns.GetApplyVariables(name, variables) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.JSON(http.StatusOK, pattern) + c.JSON(http.StatusOK, pattern) } diff --git a/restapi/serve.go b/restapi/serve.go index a9dea1f1..3b64cd32 100644 --- a/restapi/serve.go +++ b/restapi/serve.go @@ -2,24 +2,26 @@ package restapi import ( "github.com/danielmiessler/fabric/db" - "github.com/labstack/echo/v4" - "github.com/labstack/echo/v4/middleware" + "github.com/gin-gonic/gin" ) func Serve(fabricDb *db.Db, address string) (err error) { - e := echo.New() + r := gin.Default() // Middleware - e.Use(middleware.Logger()) - e.Use(middleware.Recover()) + r.Use(gin.Logger()) + r.Use(gin.Recovery()) // Register routes - NewPatternsHandler(e, fabricDb.Patterns) - NewContextsHandler(e, fabricDb.Contexts) - NewSessionsHandler(e, fabricDb.Sessions) + NewPatternsHandler(r, fabricDb.Patterns) + NewContextsHandler(r, fabricDb.Contexts) + NewSessionsHandler(r, fabricDb.Sessions) // Start server - e.Logger.Fatal(e.Start(address)) + err = r.Run(address) + if err != nil { + return err + } return } diff --git a/restapi/sessions.go b/restapi/sessions.go index 288194de..5a4d2ad0 100644 --- a/restapi/sessions.go +++ b/restapi/sessions.go @@ -2,7 +2,7 @@ package restapi import ( "github.com/danielmiessler/fabric/db" - "github.com/labstack/echo/v4" + "github.com/gin-gonic/gin" ) // SessionsHandler defines the handler for sessions-related operations @@ -12,8 +12,8 @@ type SessionsHandler struct { } // NewSessionsHandler creates a new SessionsHandler -func NewSessionsHandler(e *echo.Echo, sessions *db.SessionsEntity) (ret *SessionsHandler) { +func NewSessionsHandler(r *gin.Engine, sessions *db.SessionsEntity) (ret *SessionsHandler) { ret = &SessionsHandler{ - StorageHandler: NewStorageHandler[db.Session](e, "sessions", sessions), sessions: sessions} + StorageHandler: NewStorageHandler[db.Session](r, "sessions", sessions), sessions: sessions} return ret } diff --git a/restapi/storage.go b/restapi/storage.go index 93dcf847..faff9057 100644 --- a/restapi/storage.go +++ b/restapi/storage.go @@ -3,7 +3,7 @@ package restapi import ( "fmt" "github.com/danielmiessler/fabric/db" - "github.com/labstack/echo/v4" + "github.com/gin-gonic/gin" "io" "net/http" ) @@ -14,80 +14,87 @@ type StorageHandler[T any] struct { } // NewStorageHandler creates a new StorageHandler -func NewStorageHandler[T any](e *echo.Echo, entityType string, storage db.Storage[T]) (ret *StorageHandler[T]) { +func NewStorageHandler[T any](r *gin.Engine, entityType string, storage db.Storage[T]) (ret *StorageHandler[T]) { ret = &StorageHandler[T]{storage: storage} - e.GET(fmt.Sprintf("/%s/:name", entityType), ret.Get) - e.GET(fmt.Sprintf("/%s/names", entityType), ret.GetNames) - e.DELETE(fmt.Sprintf("/%s/:name", entityType), ret.Delete) - e.GET(fmt.Sprintf("/%s/exists/:name", entityType), ret.Exists) - e.PUT(fmt.Sprintf("/%s/rename/:oldName/:newName", entityType), ret.Rename) - e.POST(fmt.Sprintf("/%s/:name", entityType), ret.Save) + r.GET(fmt.Sprintf("/%s/:name", entityType), ret.Get) + r.GET(fmt.Sprintf("/%s/names", entityType), ret.GetNames) + r.DELETE(fmt.Sprintf("/%s/:name", entityType), ret.Delete) + r.GET(fmt.Sprintf("/%s/exists/:name", entityType), ret.Exists) + r.PUT(fmt.Sprintf("/%s/rename/:oldName/:newName", entityType), ret.Rename) + r.POST(fmt.Sprintf("/%s/:name", entityType), ret.Save) return } -func (h *StorageHandler[T]) Get(c echo.Context) error { +// Get handles the GET /storage/:name route +func (h *StorageHandler[T]) Get(c *gin.Context) { name := c.Param("name") item, err := h.storage.Get(name) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.JSON(http.StatusOK, item) + c.JSON(http.StatusOK, item) } // GetNames handles the GET /storage/names route -func (h *StorageHandler[T]) GetNames(c echo.Context) error { +func (h *StorageHandler[T]) GetNames(c *gin.Context) { names, err := h.storage.GetNames() if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.JSON(http.StatusOK, names) + c.JSON(http.StatusOK, names) } // Delete handles the DELETE /storage/:name route -func (h *StorageHandler[T]) Delete(c echo.Context) error { +func (h *StorageHandler[T]) Delete(c *gin.Context) { name := c.Param("name") err := h.storage.Delete(name) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.NoContent(http.StatusOK) + c.Status(http.StatusOK) } // Exists handles the GET /storage/exists/:name route -func (h *StorageHandler[T]) Exists(c echo.Context) error { +func (h *StorageHandler[T]) Exists(c *gin.Context) { name := c.Param("name") exists := h.storage.Exists(name) - return c.JSON(http.StatusOK, exists) + c.JSON(http.StatusOK, exists) } // Rename handles the PUT /storage/rename/:oldName/:newName route -func (h *StorageHandler[T]) Rename(c echo.Context) error { +func (h *StorageHandler[T]) Rename(c *gin.Context) { oldName := c.Param("oldName") newName := c.Param("newName") err := h.storage.Rename(oldName, newName) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.NoContent(http.StatusOK) + c.Status(http.StatusOK) } // Save handles the POST /storage/save/:name route -func (h *StorageHandler[T]) Save(c echo.Context) error { +func (h *StorageHandler[T]) Save(c *gin.Context) { name := c.Param("name") // Read the request body - body := c.Request().Body + body := c.Request.Body defer body.Close() content, err := io.ReadAll(body) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } // Save the content to storage err = h.storage.Save(name, content) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, err.Error()) + return } - return c.NoContent(http.StatusOK) + c.Status(http.StatusOK) }