Add requests package and implement JSON fetching in main.go

This commit is contained in:
2025-05-25 00:52:31 +03:00
parent 9aaefaa72b
commit 53a739e5d2
20 changed files with 22 additions and 1 deletions

1
.gitignore vendored Normal file → Executable file
View File

@@ -0,0 +1 @@
.idea

0
api/generated/v1/test.pb.go Normal file → Executable file
View File

0
api/generated/v1/test_grpc.pb.go Normal file → Executable file
View File

16
cmd/server/main.go Normal file → Executable file
View File

@@ -4,6 +4,7 @@ import (
adapters2 "Sipro-Marketplaces/internal/test/adapters"
"context"
"database/sql"
"github.com/carlmjohnson/requests"
"log"
"os"
"os/signal"
@@ -91,6 +92,21 @@ func (s *Server) shutdown() {
}
func main() {
type post struct {
Name string `json:"name"`
Language string `json:"language"`
ID string `json:"id"`
Bio string `json:"bio"`
Version float64 `json:"version"`
}
response := new([]post)
err := requests.URL("https://microsoftedge.github.io/Demos/json-dummy-data/5MB-min.json").ToJSON(&response).Fetch(context.Background())
if err != nil {
log.Fatalf("Failed to fetch URL: %v", err)
}
println(len(*response))
return
cfg := config.Load()
server, err := NewServer(cfg)
if err != nil {

1
go.mod Normal file → Executable file
View File

@@ -9,6 +9,7 @@ require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/bytedance/sonic v1.13.2 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/carlmjohnson/requests v0.24.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect

2
go.sum Normal file → Executable file
View File

@@ -11,6 +11,8 @@ github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/carlmjohnson/requests v0.24.3 h1:LYcM/jVIVPkioigMjEAnBACXl2vb42TVqiC8EYNoaXQ=
github.com/carlmjohnson/requests v0.24.3/go.mod h1:duYA/jDnyZ6f3xbcF5PpZ9N8clgopubP2nK5i6MVMhU=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=

0
internal/config/config.go Normal file → Executable file
View File

0
internal/db/conn.go Normal file → Executable file
View File

0
internal/db/schema.sql Normal file → Executable file
View File

0
internal/db/sqlc.yaml Normal file → Executable file
View File

0
internal/logger/logger.go Normal file → Executable file
View File

0
internal/test/adapters/http.go Normal file → Executable file
View File

0
internal/test/db/generated/db.go Normal file → Executable file
View File

0
internal/test/db/generated/models.go Normal file → Executable file
View File

0
internal/test/db/generated/queries.sql.go Normal file → Executable file
View File

0
internal/test/db/queries.sql Normal file → Executable file
View File

0
internal/test/repository.go Normal file → Executable file
View File

0
internal/test/service.go Normal file → Executable file
View File

0
pkg/utils/utils.go Normal file → Executable file
View File

3
pkgs Normal file → Executable file
View File

@@ -6,4 +6,5 @@ go get github.com/lib/pq
go get github.com/rs/zerolog/log
go get github.com/bytedance/sonic
go get github.com/gofiber/swagger
go get github.com/golang-jwt/jwt/v5
go get github.com/golang-jwt/jwt/v5
go get github.com/carlmjohnson/requests