Skip to content

stevenmatthewt/inquiry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

inquiry

inquiry is a simple package desiged to facilitate with handling Query String parameters in Golang HTTP Servers. It allows Query String parameters to be automatically Unmarshalled into a struct, thus promoting type safety throughout the rest of your code.

How to use

inquiry aims to maintain a very simple, intuitive interface that matches other Go packages such as json and xml.

type queryFormat struct {
    AccountID      int      `query:"account_id"`
    FirstName      string   `query:"first_name"`
    LastName       string   `query:"last_name"`
    FavoriteColors []string `query:"fav_colors"`
}

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
    var queryParameters queryFormat
    err := inquiry.UnmarshalMap(r.URL.Query(), &queryParameters)
    if err != nil {
        panic(err)
    }

    // You can now access you query parameters in a type-safe manner
    fmt.Printf("%s %s belongs to account %d",
        queryParameters.FirstName,
        queryParameters.LastName,
        queryParameters.AccountID,
    )
}

About

Golang Query String marshal/unmarshal support

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages