This service replies with useful and informative facts about printers.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd
facts
internal/printerfactsserver
rpc/printerfacts
scripts
statik
vendor
.dockerignore
.gitignore
Dockerfile
Procfile
README.md
go.mod
go.sum

README.md

printerfacts

This service replies with useful and informative facts about printers.

Default Endpoint

I have an instance of this running on Heroku.

cURL

$ curl https://printerfacts.herokuapp.com/twirp/us.xeserv.api.Printerfacts/Fact \
       -X POST -H "Content-Type: application/json" --data '{"count": 1}' | jq
{
  "facts": [
    "printers step with both left legs, then both right legs when they walk or run."
  ]
}

Go

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/Xe/printerfacts/rpc/printerfacts"
)

const defaultURL = "https://printerfacts.herokuapp.com"

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	cli := printerfacts.NewPrinterfactsProtobufClient(defaultURL, http.DefaultClient)
	fact, err := cli.Fact(ctx, &printerfacts.FactParams{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(fact.Facts[0])
}

Build

< assuming you are using a docker image derived from xena/alpine >
# apk -U add retool
$ cd /path/to/go/src/github.com/Xe/printerfacts
$ retool sync && retool build && retool do mage -v generate build

Run locally

< in one terminal >
$ ./bin/printerfacts
< in another terminal >
$ ./bin/pfact -server http://127.0.0.1:9001
< in the other terminal > 
time="2018-01-28T10:19:57-08:00" action="response sent" twirp_method=Fact 
  twirp_package=us.xeserv.api twirp_service=Printerfacts remote_ip=127.0.0.1 
  x_forwarded_for= path=/twirp/us.xeserv.api.Printerfacts/Fact 
  response_time=191.671µs