hiro

package module
v2.0.27 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

hiro 2.0

Hiro (snowcrash) is the Model Rocket project generation tool. Hiro borrows heavily from go-swagger, but builds other custom components for projects using the Model Rocket Cloud Core.

Install

Hiro uses go modules ensure the env var GO111MODULE=on is set in your .bash_profile or other appropriate location.

> go install gitlab.com/ModelRocket/hiro/v2/cmd/hiro

Project Layout

All hiro projects have the same base layout:

~~~
├── .hiro                     // The hiro project dir
├── api/                      // Generated API sources
│   └── api_name/             // The api name
│       └── rest/                 // The swagger based rest api
|       └── types/                // The api data types and models
|   └── api_name.yaml          // The swagger definition
├── functions/                                      
│   └── .../                  // Cloud functions
├── LICENSE                   // The project license

~~~

Getting started

You run hiro from with the directory you want to create a new project. This directory must be within your $(GOPATH)/src. To initialize a project you simply point it at your swagger document. This can be a file or a url, either will be copied to api/swagger.yaml

Note: hiro cannot resolve private swagger documents at this time, so all definitions must be public or contained within the same specification document. For projects that use domains or external references, setup a GitHub sync in swagger to the git branch or the project to the location above.

Initialize the project
> hiro init
Working with an API
Add an API
 > hiro api add https://api.swaggerhub.com/apis/ModelRocket/acme/1.0.0/swagger.yaml
Sync the API

If you make changes to the API, you need to sync the swagger.

> hiro api sync
Create a cloud entry point for a specific API (lambda or otherwise)
> hiro function add acme

This will create a main.go in ./functions/acme.

Environments

You can provide environment variables to a hiro function via the hiro.json file.

{
	"environment": {
		"prod": {
			"CLOUD_PROVIDER": "aws",
			"DB_DRIVER": "postgres"
		}
	}
}
Initializing the Environment

In the main package, you should call hiro.Init() at some point before using any other methods, the best place is in init.

func init() {
	hiro.Init()
}

This will ensure the environment in the hiro.json is applied.

Hiro Server

hiro provides a Server method for detecting cloud environments like AWS Lambda with a fallback to starting a local HTTP server.

if err := hiro.Serve(handler, func() {
  db.Close()
  log.Debug("database closed")
}); err != nil {
  log.Fatalln(err)
}

The method takes an http.Handler and a callback for when the service gracefully exits upon termination signal.

Documentation

Overview

Package hiro provides the hiro entry points

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Getenv added in v2.0.3

func Getenv(key string, decrypt ...bool) string

Getenv bootstraps hiro and returns the env var

func Log added in v2.0.6

func Log(name string) *logrus.Entry

Log returns a new logger, ensuring the environment is loaded first

func Lookupenv added in v2.0.3

func Lookupenv(key string) (string, bool)

Lookupenv bootstraps hiro and returns the env var

func Serve

func Serve(handler http.Handler, onExit ...func()) error

Serve starts the hiro api server with graceful exit

func Watchenv added in v2.0.3

func Watchenv(key string, value *string)

Watchenv causes the value to be updated after Init is called This is useful when a global variable must be updated before any other calls, besides init in the project

Types

This section is empty.

Directories

Path Synopsis
cmd
internal
pkg
generator
Package generator provides the code generation library for go-swagger.
Package generator provides the code generation library for go-swagger.

Jump to

Keyboard shortcuts

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