https://github.com/shoenig/extractors
Go library for defining a schema to extract values from environment variables, URL paths, or html Forms
https://github.com/shoenig/extractors
environment-variables extract extractor extractors go golang golang-library html-form url
Last synced: over 1 year ago
JSON representation
Go library for defining a schema to extract values from environment variables, URL paths, or html Forms
- Host: GitHub
- URL: https://github.com/shoenig/extractors
- Owner: shoenig
- License: bsd-3-clause
- Archived: true
- Created: 2019-06-21T17:58:38.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-11-26T14:10:01.000Z (over 1 year ago)
- Last Synced: 2025-02-20T08:33:18.008Z (over 1 year ago)
- Topics: environment-variables, extract, extractor, extractors, go, golang, golang-library, html-form, url
- Language: Go
- Homepage:
- Size: 62.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
extractors
==========
The `extractors` module provides libraries for defining a schema to easily and safely extract values from environment variables,
URL path elements, and HTML form values.

[](https://github.com/shoenig/extractors/actions/workflows/ci.yaml)
# Getting Started
The `extractors` package can be installed by running
```shell-session
go get github.com/shoenig/extractors@latest
```
```go
import (
github.com/shoenig/extractors/env // extract values from environment variables
github.com/shoenig/extractors/urlpath // extract elements from url paths
github.com/shoenig/extractors/formdata // extract values from html data
)
```
#### env example
Use the `env` package to parse values from environment variables.
```go
import github.com/shoenig/go-conceal // for storing sensitive values
```
```go
var (
go111module string
sshPID int
password *conceal.Text
)
_ = env.ParseOS(env.Schema{
"GO111MODULE": env.String(&go111module, false),
"SSH_AGENT_PID": env.Int(&sshPID, true),
"PASSWORD": env.Secret(&password, true),
})
```
#### formdata example
Use the `formdata` package to parse values from `url.Values` (typically coming
from ``*http.Request.Form` objects from inbound requests.
```go
// typically coming from a *http.Request.Form
values := url.Values{
"user": []string{"bob"},
"age": []string{"45"},
}
var (
user string
age int
)
_ = formdata.Parse(values, formdata.Schema{
"user": formdata.String(&user),
"age": formdata.Int(&age),
})
```
#### urlpath example
Use the `urlpath` package to parse URL path elements when using a `gorilla/mux`
router.
```go
// with a mux handler definition like
router.Handle("/{kind}/{id}")
// in the handler implementation, parse the *http.Request URL with
var (
kind string
id int
)
_ = urlpath.Parse(request, urlpath.Schema{
"kind": urlpath.String(&kind),
"id": urlpath.Int(&id),
})
```
# Contributing
The `github.com/shoenig/extractors` module is always improving with new features
and error corrections. For contributing bug fixes and new features please file an issue.
# License
The `github.com/shoenig/extractors` module is open source under the [BSD-3-Clause](LICENSE) license.