mirror of
https://github.com/skidoodle/ipinfo.git
synced 2026-04-28 01:27:34 +02:00
Restructure and refactor codebase
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
db "skidoodle/ipinfo/internal/db"
|
||||
iputils "skidoodle/ipinfo/utils/iputils"
|
||||
)
|
||||
|
||||
type DataStruct struct {
|
||||
IP *string `json:"ip"`
|
||||
Hostname *string `json:"hostname"`
|
||||
ASN *string `json:"asn"`
|
||||
Org *string `json:"org"`
|
||||
City *string `json:"city"`
|
||||
Region *string `json:"region"`
|
||||
Country *string `json:"country"`
|
||||
Continent *string `json:"continent"`
|
||||
Timezone *string `json:"timezone"`
|
||||
Loc *string `json:"loc"`
|
||||
}
|
||||
|
||||
// Global IP cache with 10 minute TTL
|
||||
var ipCache = NewIPCache(10 * time.Minute)
|
||||
|
||||
type cachedIPData struct {
|
||||
data *DataStruct
|
||||
time time.Time
|
||||
}
|
||||
|
||||
// IPCache provides thread-safe caching of IP lookup results
|
||||
type IPCache struct {
|
||||
cache sync.Map
|
||||
ttl time.Duration
|
||||
}
|
||||
|
||||
// NewIPCache creates a new IP cache with the specified TTL
|
||||
func NewIPCache(ttl time.Duration) *IPCache {
|
||||
return &IPCache{
|
||||
ttl: ttl,
|
||||
}
|
||||
}
|
||||
|
||||
// Set stores an IP in the cache
|
||||
func (c *IPCache) Set(ipStr string, data *DataStruct) {
|
||||
c.cache.Store(ipStr, cachedIPData{
|
||||
data: data,
|
||||
time: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// Get retrieves an IP from the cache if it exists and is not expired
|
||||
func (c *IPCache) Get(ipStr string) (*DataStruct, bool) {
|
||||
if cachedData, ok := c.cache.Load(ipStr); ok {
|
||||
cached := cachedData.(cachedIPData)
|
||||
if time.Since(cached.time) < c.ttl {
|
||||
return cached.data, true
|
||||
}
|
||||
c.cache.Delete(ipStr)
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// LookupIPData looks up IP data in the databases with caching
|
||||
func LookupIPData(geoIP *db.GeoIPManager, ip net.IP) *DataStruct {
|
||||
// Check cache first
|
||||
if data, found := ipCache.Get(ip.String()); found {
|
||||
return data
|
||||
}
|
||||
|
||||
var cityRecord struct {
|
||||
City struct {
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"city"`
|
||||
Subdivisions []struct {
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"subdivisions"`
|
||||
Country struct {
|
||||
IsoCode string `maxminddb:"iso_code"`
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"country"`
|
||||
Continent struct {
|
||||
Code string `maxminddb:"code"`
|
||||
Names map[string]string `maxminddb:"names"`
|
||||
} `maxminddb:"continent"`
|
||||
Location struct {
|
||||
Latitude float64 `maxminddb:"latitude"`
|
||||
Longitude float64 `maxminddb:"longitude"`
|
||||
Timezone string `maxminddb:"time_zone"`
|
||||
} `maxminddb:"location"`
|
||||
}
|
||||
|
||||
// Get database readers using thread-safe accessor methods
|
||||
cityDB := geoIP.GetCityDB()
|
||||
err := cityDB.Lookup(ip, &cityRecord)
|
||||
if err != nil {
|
||||
log.Printf("Error looking up city data: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var asnRecord struct {
|
||||
AutonomousSystemNumber uint `maxminddb:"autonomous_system_number"`
|
||||
AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
|
||||
}
|
||||
asnDB := geoIP.GetASNDB()
|
||||
err = asnDB.Lookup(ip, &asnRecord)
|
||||
if err != nil {
|
||||
log.Printf("Error looking up ASN data: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
hostname, err := net.LookupAddr(ip.String())
|
||||
if err != nil || len(hostname) == 0 {
|
||||
hostname = []string{""}
|
||||
}
|
||||
|
||||
var sd *string
|
||||
if len(cityRecord.Subdivisions) > 0 {
|
||||
name := cityRecord.Subdivisions[0].Names["en"]
|
||||
sd = &name
|
||||
}
|
||||
|
||||
data := &DataStruct{
|
||||
IP: ToPtr(ip.String()),
|
||||
Hostname: ToPtr(strings.TrimSuffix(hostname[0], ".")),
|
||||
ASN: ToPtr(fmt.Sprintf("%d", asnRecord.AutonomousSystemNumber)),
|
||||
Org: ToPtr(asnRecord.AutonomousSystemOrganization),
|
||||
City: ToPtr(cityRecord.City.Names["en"]),
|
||||
Region: sd,
|
||||
Country: ToPtr(cityRecord.Country.Names["en"]),
|
||||
Continent: ToPtr(cityRecord.Continent.Names["en"]),
|
||||
Timezone: ToPtr(cityRecord.Location.Timezone),
|
||||
Loc: ToPtr(fmt.Sprintf("%.4f,%.4f", cityRecord.Location.Latitude, cityRecord.Location.Longitude)),
|
||||
}
|
||||
|
||||
// Store in cache
|
||||
ipCache.Set(ip.String(), data)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// ToPtr converts string to pointer
|
||||
func ToPtr(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
// IsBogon checks if the IP is a bogon IP
|
||||
func IsBogon(ip net.IP) bool {
|
||||
for _, net := range iputils.BogonNets {
|
||||
if net.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetRealIP extracts the client's real IP address from request headers
|
||||
func GetRealIP(r *http.Request) string {
|
||||
// Try common proxy headers first
|
||||
for _, header := range []string{"CF-Connecting-IP", "X-Real-IP", "X-Forwarded-For"} {
|
||||
if ip := r.Header.Get(header); ip != "" {
|
||||
return strings.TrimSpace(strings.Split(ip, ",")[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to remote address
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return host
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
)
|
||||
|
||||
// Database paths
|
||||
const (
|
||||
CityDBPath = "./GeoLite2-City.mmdb"
|
||||
ASNDBPath = "./GeoLite2-ASN.mmdb"
|
||||
)
|
||||
|
||||
// Common errors
|
||||
var (
|
||||
ErrDatabaseNotFound = errors.New("database file not found")
|
||||
ErrDatabaseOpen = errors.New("failed to open database")
|
||||
ErrDownloadFailed = errors.New("failed to download database")
|
||||
)
|
||||
|
||||
// Handles MaxMind GeoIP database operations
|
||||
type GeoIPManager struct {
|
||||
cityDB *maxminddb.Reader
|
||||
asnDB *maxminddb.Reader
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
// Creates and initializes a new GeoIP database
|
||||
func NewGeoIPManager() (*GeoIPManager, error) {
|
||||
manager := &GeoIPManager{}
|
||||
if err := manager.Initialize(); err != nil {
|
||||
return nil, fmt.Errorf("initializing GeoIP manager: %w", err)
|
||||
}
|
||||
return manager, nil
|
||||
}
|
||||
|
||||
// Initialize opens the GeoIP databases, downloading them if necessary
|
||||
func (g *GeoIPManager) Initialize() error {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
if err := g.openCityDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := g.openASNDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Opens the city database, downloading it if necessary
|
||||
func (g *GeoIPManager) openCityDB() error {
|
||||
var err error
|
||||
g.cityDB, err = maxminddb.Open(CityDBPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Println("City database not found, attempting to download...")
|
||||
if err := g.downloadDatabases(); err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrDownloadFailed, err)
|
||||
}
|
||||
g.cityDB, err = maxminddb.Open(CityDBPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w (city): %v", ErrDatabaseOpen, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%w (city): %v", ErrDatabaseOpen, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Opens the ASN database, downloading it if necessary
|
||||
func (g *GeoIPManager) openASNDB() error {
|
||||
var err error
|
||||
g.asnDB, err = maxminddb.Open(ASNDBPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Println("ASN database not found, attempting to download...")
|
||||
if err := g.downloadDatabases(); err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrDownloadFailed, err)
|
||||
}
|
||||
g.asnDB, err = maxminddb.Open(ASNDBPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w (ASN): %v", ErrDatabaseOpen, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%w (ASN): %v", ErrDatabaseOpen, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Downloads both GeoIP databases using geoipupdate
|
||||
func (g *GeoIPManager) downloadDatabases() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, "geoipupdate", "-d", "./")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download databases: %v. Output: %s. Ensure geoipupdate is installed and configured", err, output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close properly closes the database readers
|
||||
func (g *GeoIPManager) Close() error {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
var errs []error
|
||||
|
||||
if g.cityDB != nil {
|
||||
if err := g.cityDB.Close(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("closing city database: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
if g.asnDB != nil {
|
||||
if err := g.asnDB.Close(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("closing ASN database: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return fmt.Errorf("errors closing databases: %v", errs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Safely provides read access to the City database
|
||||
func (g *GeoIPManager) GetCityDB() *maxminddb.Reader {
|
||||
g.mu.RLock()
|
||||
defer g.mu.RUnlock()
|
||||
return g.cityDB
|
||||
}
|
||||
|
||||
// Safely provides read access to the ASN database
|
||||
func (g *GeoIPManager) GetASNDB() *maxminddb.Reader {
|
||||
g.mu.RLock()
|
||||
defer g.mu.RUnlock()
|
||||
return g.asnDB
|
||||
}
|
||||
|
||||
// Sets up automatic database updates
|
||||
func (g *GeoIPManager) StartUpdater(ctx context.Context, updateInterval time.Duration) {
|
||||
log.Printf("Starting MaxMind GeoIP database updater with interval: %s", updateInterval)
|
||||
|
||||
ticker := time.NewTicker(updateInterval)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
log.Println("Performing scheduled GeoIP database update")
|
||||
if err := g.UpdateDatabases(); err != nil {
|
||||
log.Printf("Failed to update databases: %v", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
ticker.Stop()
|
||||
log.Println("GeoIP database updater stopped")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Downloads fresh copies of the databases and reloads them
|
||||
func (g *GeoIPManager) UpdateDatabases() error {
|
||||
// Download new databases
|
||||
if err := g.downloadDatabases(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
// Close existing databases
|
||||
if g.cityDB != nil {
|
||||
if err := g.cityDB.Close(); err != nil {
|
||||
log.Printf("Warning: error closing city database: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if g.asnDB != nil {
|
||||
if err := g.asnDB.Close(); err != nil {
|
||||
log.Printf("Warning: error closing ASN database: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Reopen databases
|
||||
var err error
|
||||
g.cityDB, err = maxminddb.Open(CityDBPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reopening city database: %w", err)
|
||||
}
|
||||
|
||||
g.asnDB, err = maxminddb.Open(ASNDBPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reopening ASN database: %w", err)
|
||||
}
|
||||
|
||||
log.Println("Successfully updated and reloaded GeoIP databases")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
common "skidoodle/ipinfo/internal/common"
|
||||
db "skidoodle/ipinfo/internal/db"
|
||||
utils "skidoodle/ipinfo/utils/health"
|
||||
)
|
||||
|
||||
type bogonDataStruct struct {
|
||||
IP string `json:"ip"`
|
||||
Bogon bool `json:"bogon"`
|
||||
}
|
||||
|
||||
type gzipResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
Writer *gzip.Writer
|
||||
}
|
||||
|
||||
func (w gzipResponseWriter) Write(b []byte) (int, error) {
|
||||
return w.Writer.Write(b)
|
||||
}
|
||||
|
||||
// HTTP server and its dependencies
|
||||
type Server struct {
|
||||
geoIP *db.GeoIPManager
|
||||
server *http.Server
|
||||
shutdownSignal chan struct{}
|
||||
}
|
||||
|
||||
// Creates a new server with the given GeoIPManager
|
||||
func NewServer(geoIP *db.GeoIPManager) *Server {
|
||||
s := &Server{
|
||||
geoIP: geoIP,
|
||||
shutdownSignal: make(chan struct{}),
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/health", utils.HealthCheck()) // Register healthcheck
|
||||
mux.HandleFunc("/", s.handler) // Main handler
|
||||
|
||||
// Create HTTP server
|
||||
s.server = &http.Server{
|
||||
Addr: ":3000",
|
||||
Handler: mux,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Starts the HTTP server
|
||||
func (s *Server) Start(ctx context.Context) error {
|
||||
// Start the server in a goroutine
|
||||
go func() {
|
||||
log.Println("Server listening on :3000")
|
||||
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("Server error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for shutdown signal or context cancellation
|
||||
select {
|
||||
case <-s.shutdownSignal:
|
||||
log.Println("Shutdown requested internally")
|
||||
case <-ctx.Done():
|
||||
log.Println("Shutdown requested from context")
|
||||
}
|
||||
|
||||
// Create shutdown context with timeout
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Shutdown the server
|
||||
if err := s.server.Shutdown(shutdownCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Server shutdown complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Graceful server shutdown
|
||||
func (s *Server) Shutdown() {
|
||||
close(s.shutdownSignal)
|
||||
}
|
||||
|
||||
// Field access functions map
|
||||
var fieldMap = map[string]func(*common.DataStruct) *string{
|
||||
"ip": func(d *common.DataStruct) *string { return d.IP },
|
||||
"hostname": func(d *common.DataStruct) *string { return d.Hostname },
|
||||
"asn": func(d *common.DataStruct) *string { return d.ASN },
|
||||
"org": func(d *common.DataStruct) *string { return d.Org },
|
||||
"city": func(d *common.DataStruct) *string { return d.City },
|
||||
"region": func(d *common.DataStruct) *string { return d.Region },
|
||||
"country": func(d *common.DataStruct) *string { return d.Country },
|
||||
"continent": func(d *common.DataStruct) *string { return d.Continent },
|
||||
"timezone": func(d *common.DataStruct) *string { return d.Timezone },
|
||||
"loc": func(d *common.DataStruct) *string { return d.Loc },
|
||||
}
|
||||
|
||||
// Retrieves a field from the dataStruct using the fieldMap
|
||||
func getField(data *common.DataStruct, field string) *string {
|
||||
if f, ok := fieldMap[field]; ok {
|
||||
return f(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Processes HTTP requests
|
||||
func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
|
||||
requestedThings := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||
|
||||
// Enable gzip compression if requested
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
gz := gzip.NewWriter(w)
|
||||
defer gz.Close()
|
||||
w = &gzipResponseWriter{Writer: gz, ResponseWriter: w}
|
||||
}
|
||||
|
||||
var IPAddress, field string
|
||||
|
||||
// Parse the request URL
|
||||
switch len(requestedThings) {
|
||||
case 0:
|
||||
IPAddress = common.GetRealIP(r) // Default to visitor's IP
|
||||
case 1:
|
||||
if requestedThings[0] == "" {
|
||||
IPAddress = common.GetRealIP(r) // Handle root page case
|
||||
} else if _, ok := fieldMap[requestedThings[0]]; ok {
|
||||
IPAddress = common.GetRealIP(r)
|
||||
field = requestedThings[0]
|
||||
} else if net.ParseIP(requestedThings[0]) != nil {
|
||||
IPAddress = requestedThings[0] // Valid IP provided
|
||||
} else {
|
||||
sendJSONError(w, "Please provide a valid IP address.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
case 2:
|
||||
IPAddress = requestedThings[0]
|
||||
if _, ok := fieldMap[requestedThings[1]]; ok {
|
||||
field = requestedThings[1]
|
||||
} else {
|
||||
sendJSONError(w, "Please provide a valid field.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
default:
|
||||
sendJSONError(w, "Please provide a valid IP address.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Validate the resolved IP
|
||||
ip := net.ParseIP(IPAddress)
|
||||
if ip == nil {
|
||||
sendJSONError(w, "Please provide a valid IP address.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the IP is bogon
|
||||
if common.IsBogon(ip) {
|
||||
sendJSONResponse(w, bogonDataStruct{IP: ip.String(), Bogon: true}, http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
// Look up IP data
|
||||
data := common.LookupIPData(s.geoIP, ip)
|
||||
if data == nil {
|
||||
sendJSONError(w, "Please provide a valid IP address.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle specific field requests
|
||||
if field != "" {
|
||||
value := getField(data, field)
|
||||
sendJSONResponse(w, map[string]*string{field: value}, http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
// Default case: return full IP data
|
||||
sendJSONResponse(w, data, http.StatusOK)
|
||||
}
|
||||
|
||||
// Sends a JSON response with the given data and status code
|
||||
func sendJSONResponse(w http.ResponseWriter, data any, statusCode int) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(statusCode)
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
if err := encoder.Encode(data); err != nil {
|
||||
log.Printf("Error encoding JSON response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Sends a JSON error response
|
||||
func sendJSONError(w http.ResponseWriter, errMsg string, statusCode int) {
|
||||
sendJSONResponse(w, map[string]string{"error": errMsg}, statusCode)
|
||||
}
|
||||
|
||||
// Initializes and starts the server with the given GeoIPManager
|
||||
func StartServer(ctx context.Context, geoIP *db.GeoIPManager) error {
|
||||
// Create new server with the GeoIPManager
|
||||
server := NewServer(geoIP)
|
||||
|
||||
// Set up signal handling for graceful shutdown
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// Handle shutdown signals
|
||||
go func() {
|
||||
select {
|
||||
case <-sigCh:
|
||||
log.Println("Received termination signal")
|
||||
server.Shutdown()
|
||||
case <-ctx.Done():
|
||||
log.Println("Context cancelled")
|
||||
server.Shutdown()
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the server
|
||||
return server.Start(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user