rest_server

command module
v0.0.0-...-e224c93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Example: REST server

Simple HTTP/JSON REST server implemented in Go, using go-chi for HTTP routing.

To run this, cd to the root of this git repo, then run these steps:

  1. cd into an empty directory

    $ mkdir ~/template_tmp
    $ cd ~/template_tmp
    
  2. Install the abc binary

    $ go install github.com/abcxyz/abc/cmd/abc@latest
    $ abc --help
    

    This only works if you have go installed (https://go.dev/doc/install) and have the Go binary directory in your $PATH (try PATH=$PATH:~/go/bin).

  3. Execute the template defined in the t directory. This will output a file named main.go in your working directory containing the transformed program.

    $ abc templates render github.com/abcxyz/abc.git//t/rest_server
    
  4. Run the transformed program:

    $ go run .
    [yyyy/mm/dd hh:mm:ss] starting server on 8080
    
  5. In a separate shell, run:

    $ curl localhost:8080
    {"message":"hello world"}
    

Documentation

Overview

Package main implements a simple HTTP/JSON REST example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL