Skip to content

Latest commit

 

History

History
171 lines (139 loc) · 6.7 KB

README.md

File metadata and controls

171 lines (139 loc) · 6.7 KB

logo

🔗 Table of Contents

What?

go-queryparser parses a common "q" http GET variable to strip out filters, which can be used for advanced searching, like:

Hello World tags:example,world foo:"something quoted" author:lrstanley

Use:

go get -u github.com/lrstanley/go-queryparser/v3@latest

Example:

package main

import (
	"fmt"
	"net/http"

	"github.com/lrstanley/go-queryparser/v3"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		q := queryparser.Parse(r.FormValue("q"))
		if q.Has("author") {
			fmt.Fprintf(w, "filtering by author %q!", q.GetOne("author"))
			return
		}

		fmt.Fprint(w, "no filtering requested!")
	})

	http.ListenAndServe(":8080", nil)
}
$ curl -s localhost:8080
no filtering requested!
$ curl -s 'localhost:8080?q=author:"liam"'
filtering by author "liam"!

The main benefit is for user input boxes where you want additional filtering, like the Github issues search box, or similar.

🙋‍♂️ Support & Assistance

  • ❤️ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 🙋‍♂️ Take a look at the support document on guidelines for tips on how to ask the right questions.
  • 🐞 For all features/bugs/issues/questions/etc, head over here.

🤝 Contributing

  • ❤️ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 📋 Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
  • 🗝️ For anything security related, please review this repositories security policy.

⚖️ License

MIT License

Copyright (c) 2017 Liam Stanley <me@liamstanley.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Also located here