This is a trivial http server that serves json from the EndPoints defined in the yaml config file. I was interested in looking at the net/http and yaml packages, and mocking up some apis. The size/lines of the code for this nano server is surpisingly small.
An example yaml configuration:
---
server:
name: nanoserver
version: 0.0.2
maxUriRequest: 2048
port: 8080
root: /Users/foobar/golang/src/nanoserv/
endPoints:
- name: hello1
uri: /hello1/
relpath: /root/hello1/
data: index.json
- name: hello2
uri: /hello2
relpath: root//hello2/
data: foo.jsonNote that relpath is a path relative to the root path, that is with a
relpath: /root/hello1/
AND
root: /Users/foobar/golang/src/nanoserv/
the filesystem path would be
/Users/foobar/golang/src/nanoserv/root/hello1/index.json
Note, the paths are cleaned up in the config code. For this example, the endpoint
would return
/Users/foobar/golang/src/nanoserv/root/hello1/index.json
AND
would return
/Users/foobar/golang/src/nanoserv/root/hello2/foo.json
For basic server info and endpoint discovery, the
would return
{ "EndPoints":["/hello1/","/hello2/"],
"ServerName":["nanoserver"],
"Version":["0.0.2"] }To build and run this simple utility:
$ go get github.com/gorilla/handlers github.com/gorilla/mux gopkg.in/yaml.v2
$ go build
$ go installAssuming you have the go bin path in your PATH:
$ nanoserv config.yml