https://github.com/bfontaine/ephemeral
Ephemeral Web server in Go
https://github.com/bfontaine/ephemeral
go library web
Last synced: over 1 year ago
JSON representation
Ephemeral Web server in Go
- Host: GitHub
- URL: https://github.com/bfontaine/ephemeral
- Owner: bfontaine
- License: mit
- Created: 2015-04-26T13:13:04.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-26T13:37:31.000Z (about 11 years ago)
- Last Synced: 2025-03-23T23:43:40.212Z (over 1 year ago)
- Topics: go, library, web
- Language: Go
- Homepage: https://godoc.org/github.com/bfontaine/ephemeral
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ephemeral
`ephemeral` is a lightweight library to fire an ephemeral Web server. It’s
useful when you’re writing a CLI app which needs to authenticate against a
remote server using a callback URI.
[](https://godoc.org/github.com/bfontaine/ephemeral)
[](https://travis-ci.org/bfontaine/ephemeral)
## Usage
Ephemeral provides a small `http`-like API. Start by creating a server:
```go
s := ephemeral.New()
```
Then declare your handler like you’d do with a classic HTTP server, except that
it takes the server as its first argument:
```go
s.HandleFunc("/", func(s *ephemeral.Server,
w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Ok bye :)\n"))
s.Stop("foo")
})
```
The server exposes a `Stop` method which takes one argument that can be
whatever you want, including `nil`.
Start the server:
```go
s.Listen(":8080")
```
The method won’t return until the server is stopped. It returns the argument
you gave to the `.Stop()` call as well as an `error`.
## Install
go get github.com/bfontaine/ephemeral