gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/README.md (about) 1 <div align="center"> 2 <img src="./assets/logo.png" width="200" alt="Ignition Robotics" /> 3 <h1>Ignition Robotics</h1> 4 <p>Ignition Go is a general purpose golang library that encapsulates a set of common functionalities for a webserver.</p> 5 </div> 6 7 ## Getting started 8 Ignition Go provides a set of features to help with web server development. It is a set of tools that were chosen to solve different problems in [fuelserver](https://gitlab.com/ignitionrobotics/web/fuelserver) and [cloudsim](https://gitlab.com/ignitionrobotics/web/cloudsim) packages. 9 10 ### Features 11 - A custom router based on the [gorilla/mux](https://github.com/gorilla/mux) package. 12 - A thread-safe concurrent queue based on the [enriquebris/goconcurrentqueue](https://github.com/enriquebris/goconcurrentqueue) package. 13 - A scheduler to set jobs to be executed at certain dates, based on the [ignitionrobotics/web/scheduler](https://gitlab.com/ignitionrobotics/web/scheduler) package. 14 - A custom logger based on the default log package but including a [rollbar](https://github.com/rollbar/rollbar-go) implementation. 15 - An error handler with a list of default and custom error messages. 16 17 ## Usage 18 19 ### Routes 20 ```go 21 ign.Routes{ 22 ign.Route{ 23 Name: "Route example", 24 Description: "Route description example", 25 URI: "/example", 26 Headers: ign.AuthHeadersRequired, 27 Methods: ign.Methods{ 28 ign.Method{ 29 Type: "GET", 30 Description: "Get all the examples", 31 Handlers: ign.FormatHandlers{ 32 ign.FormatHandler{ 33 Extension: "", 34 Handler: ign.JSONResult(/* Your method handler in here */), 35 }, 36 }, 37 }, 38 }, 39 SecureMethods: ign.SecureMethods{ 40 ign.Method{ 41 Type: "POST", 42 Description: "Creates a new example", 43 Handlers: ign.FormatHandlers{ 44 ign.FormatHandler{ 45 Extension: "", 46 Handler: ign.JSONResult(/* Your secure method handler in here */), 47 }, 48 }, 49 }, 50 }, 51 }, 52 } 53 ``` 54 55 ### Queue 56 ```go 57 func main() { 58 queue := ign.NewQueue() 59 queue.Enqueue("Value") 60 if v, err := queue.DequeueOrWaitForNextElement(); err == nil { 61 fmt.Println(v) 62 } 63 } 64 ``` 65 66 ### Scheduler 67 ```go 68 func main() { 69 s := scheduler.GetInstance() 70 s.DoAt(example, time.Now().Add(5*time.Second)) 71 } 72 73 func example() { 74 fmt.Println("Scheduled task") 75 } 76 ``` 77 78 ## Installing 79 ### Using Go CLI 80 ``` 81 go get gitlab.com/ignitionrobotics/web/ign-go.git 82 ``` 83 84 ## Contribute 85 **There are many ways to contribute to Ignition Go.** 86 - Reviewing the source code changes. 87 - Report new bugs. 88 - Suggest new packages that we should consider including. 89 90 ## Environment variables 91 - **IGN_SSL_CERT**: Path to an SSL certificate file. This is used for local SSL testing and development. 92 - **IGN_SSL_KEY**: Path to an SSL key. THis is used for local SSL testing and development 93 - **IGN_DB_USERNAME**: Username for the database connection. 94 - **IGN_DB_PASSWORD**: Password for the database connection. 95 - **IGN_DB_ADDRESS**: URL address for the database server. 96 - **IGN_DB_NAME**: Name of the database to use on the database sever. 97 - **IGN_DB_LOG**: Controls whether or not database transactions generate log output. Set to true to enable database logging. This environment variable is optional, and database logging will default to off expect for tests. 98 - **IGN_DB_MAX_OPEN_CONNS**: Max number of open connections in connections pool. A value <= 0 means unlimited connections. Tip: You can learn max_connections of your mysql by running this query: SHOW VARIABLES LIKE "max_connections"; 99 - **IGN_GA_TRACKING_ID**: Google Analytics Tracking ID to use. If not set, then GA will not be enabled. The format is UA-XXXX-Y. 100 - **IGN_GA_APP_NAME**: Google Analytics Application Name. If not set, then GA will not be enabled. 101 - **IGN_GA_CAT_PREFIX**: (optional) A string to use as a prefix to Google Analytics Event Category. 102 - **IGN_ROLLBAR_TOKEN**: (optional) Rollbar authentication token. If valid, then log messages will be sent to rollbar.com. It is recommended NOT to use rollbar during local development. 103 - **IGN_ROLLBAR_ENV**: (optional) Rollbar environment string, such as "staging" or "production". 104 - **IGN_ROLLBAR_ROOT**: (optional) Path to the application code root, not including the final slash. Such as bitbucket.org/ignitionrobotics/ign-fuelserver 105 - **IGN_LOGGER_LOG_STDOUT**: (optional) Controls whether or not logs will be also sent to stdout/err. If missing, a false value will be used.