go/

directory
v0.0.0-...-ce83e3f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: BSD-2-Clause

README

Go Tutorial

In this tutorial we will generate a simple Go client & server from an RAML file and then integrate it with itsyou.online authorization server.

This tutorial use jumpscale/ubuntu1604_golang docker image. But you can use any system with Go installed and configured.

Create docker instances

You can skip this step if you want to use your own enviroment.

sudo docker pull jumpscale/ubuntu1604_golang
sudo docker run --rm -t -i  --name=goraml jumpscale/ubuntu1604_golang

Server

Generate server code by using this command

$ go-raml server --ramlfile ../api.raml --import-path examples.com/goramldir --dir $GOPATH/src/examples.com/goramldir

You can find all server files in $GOPATH/src/examples.com/goramldir directory.

Server side itsyou.online integration

You only need to replace the value of oauth2ServerPublicKey variable in oauth2_itsyouonline_middleware.go to the content of itsyouonline.pub.

Build & Run the server

go build
./goramldir

Client

generate client code by using this command

go-raml client --ramlfile ../api.raml --dir client/goramldir --package goramldir

Then you can find client code in client directory.

simple client main program

A simple example of the client program can be found in main.go.

Steps to use generated client lib:

  • create goramldir client object
  • create itsyou.online JWT token
  • set JWT token as authorization header

after above steps, client are ready to make API call to goramldir server.

The code is relatively simple and have enough comment, so it should be easy to understand.

execute client program

go build
./client --app_id=YOUR_APP_ID --app_secret=YOUR_API_KEY

Auto Generated API server homepage & API Docs

go-raml generated code also provide you with a simple homepage and auto generated API docs.

To access it, you can visit http://localhost:5000 from your browser

API server homepage

If we click API Docs, browser will go to auto generated API docs page

API Docs

We can click any HTTP verbs in the API Docs page to see documentation for that endpoint & verb. This is documentation for POST /users page

POST /users

Directories

Path Synopsis
goramldir
DO NOT EDIT THIS FILE.
DO NOT EDIT THIS FILE.
goramldir/goraml
DO NOT EDIT THIS FILE.
DO NOT EDIT THIS FILE.
goramldir/types
DO NOT EDIT THIS FILE.
DO NOT EDIT THIS FILE.

Jump to

Keyboard shortcuts

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