构建并运行go程序的单个实例

网友投稿 668 2022-10-21

构建并运行go程序的单个实例

构建并运行go程序的单个实例

Build and run a single instance of a go program.

Use this plugin in conjunction with grunt-contrib-watch to reload your go app automatically on every code change.

Alternatively, use this plugin to build and run your go app forever using the go_reload task.

This plugin is built on Grunt 1.0.1 but should work on earlier versions.

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-go-reload --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks("grunt-go-reload");

The "go_reload" task

Overview

In your project's Gruntfile, add a section named go_reload to the data object passed into grunt.initConfig().

grunt.initConfig({ go_reload: { app: { name: "sample-go-app", port: 3000 } },});

Options

options.name

Type: String Default value: None

A string value used in the go build compilation step to name the output executable (using the go build -o option). See go build -h for more details.

options.port

Type: Number Default value: 3000

A number assigned to the PORT environment variable when executing your go app. Access this value in go using os.Getenv("PORT").

options.background

Type: Boolean Default value: false

Use false to make go_reload block Grunt in order to keep it running. Use true if configuring with grunt-contrib-watch to reload your go app automatically on every code change. See Watch Configuration for specifics.

options.env

Type: Object Default value: undefined

These values will be passed as environment variables when executing your go app. Access these value in go using os.Getenv(...). For example:

grunt.initConfig({ go_reload: { app: { name: "sample-go-app", port: 3000, env: { GO_ENV: "development", API_KEY: "0123456789" } } },});

Usage Examples

Basic Configuration

Use this configuration to have Grunt build and run your go app forever.

grunt.initConfig({ go_reload: { app: { name: "sample-go-app", port: 3000 } },});grunt.loadNpmTasks("grunt-go-reload");grunt.registerTask("default", ["go_reload"]);

Watch Configuration

Use this configuration to have Grunt reload your go app on every code change using grunt-contrib-watch.

grunt.initConfig({ go_reload: { app: { name: "sample-go-app", port: 3000, background: true } }, watch: { options: { atBegin: true }, go: { files: ["**/*.go"], tasks: ["go_reload"] } }});grunt.loadNpmTasks("grunt-go-reload");grunt.loadNpmTasks("grunt-contrib-watch");grunt.registerTask("default", ["watch"]);

Contributing

This plugin was created to service a basic go web app so pull requests / issues to make this plugin work with your project are welcome!

Release History

(March 27, 2017) v0.1.2: Add support for env parameter in the grunt config(March 27, 2017) v0.1.1: Fix usage of const when let was intended, Arrange and expand test coverage(March 23, 2017) v0.1.0: Initial release

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:sh - 一个shell解析器和格式化程序
下一篇:基于 Roslyn 的 C# 动态程序集构建库
相关文章

 发表评论

暂时没有评论,来抢沙发吧~