Skip to content

Instantly share code, notes, and snippets.

@mdnurahmed
Last active December 2, 2020 00:53
Show Gist options
  • Save mdnurahmed/5c375bfe4390c77924bb3544453b7687 to your computer and use it in GitHub Desktop.
Save mdnurahmed/5c375bfe4390c77924bb3544453b7687 to your computer and use it in GitHub Desktop.
It's dummy server for the "peculiar crawler" problem
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
const (
no_of_id = 1000000
)
type User struct {
Name string
Age int
}
var userTable map[string]User
func userHandler(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, userTable[id])
}
func main() {
userTable = make(map[string]User)
rand.Seed(time.Now().UTC().UnixNano())
for i := 1; i <= no_of_id; i++ {
newuser := User{
Name: fmt.Sprintf("user %d", i),
}
//random number between 10 to 60
newuser.Age = rand.Intn(50) + 10
userTable[fmt.Sprintf("%d", i)] = newuser
}
router := gin.Default()
router.GET("/user/:id", userHandler)
router.Run(":8080")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment