User Directory Project – GinGonic golang framework 13

User Directory Project – GinGonic golang framework 13

Source Code

// Let Create User directory / Phone Directory // book finding/search system
package main
import "github.com/gin-gonic/gin"
func main() {
    type User struct {
        Username string
        City     string
        Phone    string
        // every first letter should be capital
    }
    // this end of our STRUCT.. struct is custom variable
    // collection of different variables and not data
    // lets create our database
    data_users := []User{
        // enter data in our database/ slice/array
        {"ali", "dehli", "321321321"},
        {"sai", "kabul", "421321321"},
        {"alina", "dehli", "821321321"},
        {"alishba", "Madina", "921321321"},
        {"alia", "Newyork", "721321321"},
        // our data entry is complete.. lets focus on search
    }
    // create server
    r := gin.Default()
    // Get request & query string
    // user... city... phone#
    r.GET("/", func(c *gin.Context) {
        user := c.Query("user")
        city := c.Query("city")
        phone := c.Query("phone")
        // lets create our users database
        // but we need struct first
        // range .. loop through database
        for _, userdata := range data_users {
            if user == userdata.Username || city == userdata.City || phone == userdata.Phone {
                c.String(200, "Hello %s from %s and phone # %s",
                    userdata.Username, userdata.City, userdata.Phone)
                // return to end loop
                return
            }
            // if no data found
        }
        c.String(200, "No User Found...")
    })
    r.Run()
}

TAGS#

gin gonic tutorial
gin-gonic / examples
gin-gonic documentation
gin framework tutorial
gin web framework
gin router
golang gin context
gin router group

###Buy Me a Coffee https://www.buymeacoffee.com/khan1

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: