Add requests package and implement JSON fetching in main.go
This commit is contained in:
		
							
								
								
									
										16
									
								
								cmd/server/main.go
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										16
									
								
								cmd/server/main.go
									
									
									
									
									
										
										
										Normal file → Executable 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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user