gomoku
can help you make a HTTP server written in your favorite languages.
$ gomoku init sample
$ cd sample
$ gomoku run --port 8080 --file ./gomoku.yml
$ curl -v -H 'x-gomoku:yes' http://localhost:8080/foo
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /foo HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> x-gomoku:yes
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Thu, 28 Dec 2017 14:17:23 GMT
< Content-Length: 61
<
* Connection #0 to host localhost left intact
{"greeting": "hello, gomoku", "method": "GET", "url": "/foo"}
To see example configurations, please visit this page.
- request:
method: get|post
route: /foo
headers:
x-gomoku: yes
method
is a regular expression of an HTTP request method.
route
is a regular expression of an HTTP request URL.
headers
is a list of a regular expression of an HTTP request headers.
In command
block, users can use .Request
object at the inside of a template literal.
- command:
env:
- GOMOKU=gomoku
- METHOD={{ .Request.Method }}
path: python3
args:
- -m
- foo
- '{{ .Request.URL.Path }}'
env
will be exported before executing command.
path
is a path to executable command.
args
will be passed as command line arguments to executable command.
In response
block, users can use .Request
object and .Command
object at the inside of a template literal.
- response:
status: 200
headers:
content-type: application/json; charset=utf-8
cookies:
- name: session-id
value: 12345
path: /
domain: localhost
expires: 2018-01-14 22:47:17 JST
maxage: 0
secure: false
httponly: false
body: >
{
"greeting": "{{ .Command.ParseStdoutAsJson.greet }}",
"method": "{{ .Command.ParseStdoutAsJson.method }}",
"url": "{{ .Command.ParseStdoutAsJson.url }}"
}
status
is an HTTP response status code.
To redirect, set status
to 301
, 302
, 303
, 307
, 308
.
headers
is an HTTP response headers.
cookies
is an HTTP response cookies.
body
is an HTTP response body.
template
is a path to a template file representing an HTTP response body.
If body
is set in the same response
block, body
will be used instead of template
.
file
is a path to a content file representing an HTTP response body.
If body
(or template
) is set in the same response
block, body
(or template
) will be used instead of file
.
To generate textual outputs, see an API document of the Go standard template engine.
-
.GetByKey(map of string to string array, string)
: returnsstring array
-
.GetByIndex(string array, integer)
: returnsstring
-
.JoinWith(string array, string)
: returns joinedstring array
-
.ReadFile(string)
: returnsstring
that is a content of the first of uploaded file -
.ReadFiles(string)
: returnsstring array
that is a list of a content of uploaded files
-
.Method
: HTTP request method (string
) -
.URL
: HTTP request URL (net/url
'sURL
) -
.Headers
: HTTP request headers (map of string to string array
) -
.RemoteAddr
: a remote address of an HTTP request (string
) -
.Body
: HTTP request body (string
ormap
) -
.ParseBodyAsJson()
: returnsJSON
object made from.Body
(map
) -
.ParseBodyAsYaml()
: returnsYAML
object made from.Body
(map
) -
.Form
: HTTP request form (map of string to string array
)
-
.Env
: exported variables (string=string array
) -
.Path
: path to executable command (string
) -
.Args
: command line arguments (any array
) -
.Dir
: working directory (string
) -
.Stdout
: standard output stream of executable command (string
) -
.ParseStdoutAsJson()
: returnsJSON
object made from.Stdout
(map
) -
.ParseStdoutAsYaml()
: returnsYAML
object made from.Stdout
(map
) -
.Stderr
: standard error stream of executable command (string
) -
.ParseStderrAsJson()
: returnsJSON
object made from.Stderr
(map
) -
.ParseStderrAsYaml()
: returnsYAML
object made from.Stderr
(map
)
$ go get -u github.com/ohtomi/gomoku/cmd/gomoku
Or clone the repository and run:
$ make install
Or get binary from release page.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT