Skip to content

HyperplaneOrg/nanoserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nanoserv

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.

The configuration schema

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.json

Note 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

http://localhost:8080/hello1/

would return

/Users/foobar/golang/src/nanoserv/root/hello1/index.json

AND

http://localhost:8080/hello2/

would return

/Users/foobar/golang/src/nanoserv/root/hello2/foo.json

For basic server info and endpoint discovery, the

http://localhost:8080/

would return

{ "EndPoints":["/hello1/","/hello2/"],
  "ServerName":["nanoserver"],
  "Version":["0.0.2"] }

Build and Run

To build and run this simple utility:

$ go get github.com/gorilla/handlers github.com/gorilla/mux gopkg.in/yaml.v2
$ go build
$ go install

Assuming you have the go bin path in your PATH:

$ nanoserv config.yml

About

A trivial http server that serves json from the end points defined in a yaml config file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages