Adding Custom Golang Code or Dependencies to the App
You can use custom Golang code with your extensions. You can also use custom Golang code in your Flogo apps directly without using it in any extension. Your custom extensions and apps may also have dependencies. In the case of both, the custom Golang code and the dependencies, you have the option to either dynamically pull the latest version of the packages from
github.com during build time, or to pull a specific version of the package and store it locally in
<FLOGO_HOME>/lib/ext/src folder ahead of time. Storing a specific version of the package locally reduces your build time. Since the packages will be available locally, the build process saves the time it takes to pull them from an external source. Keep in mind that when the packages are pulled from the
github.com repository during build time, the absolute latest version of the packages get pulled. So, if you want a specific version of the package, you must pull the package ahead of time and store it locally.
When you build the app binary, the build process first searches for the packages locally. If it does not find a package locally, it attempts to pull the package from
github.com repository.
Adding custom Golang code to your app
<FLOGO_HOME>/lib/ext/src folder, it will be a part of all apps built from that environment.
If you want to plug in a custom Golang code and include it as a part of your engine binary or Flogo app, you can use one of the following two methods:
- Pull and place the package in
<FLOGO_HOME>/lib/ext/srcdirectoryOr
- Add the package to
deps.go
To incorporate it into your build environment, do the following:
- Pull the package from the Git repository ahead of time. This is not required if you want the package pulled dynamically during build time.
- Pull the package from the external Git repository (
github.com) to your local environment. - Place the package in
<FLOGO_HOME>/lib/ext/srcfolder. - Copy any dependent Golang packages required by your custom code into
<FLOGO_HOME>/lib/ext/srcfolder.Note: Skipping this step pulls the latest versions of the dependencies at build time.
- Pull the package from the external Git repository (
- Create a
deps.gofile under<FLOGO_HOME>/lib/ext/srcfolder if it does not already exist, and add an entry for the package pointing to its public URL.Here are two examples of the
deps.gofile content:package main import _ "github.com/<username>/contrib/eventlistener"
package main import ( _ "github.com/<username>/contrib/eventlistener" _ "github.com/<username>/contrib/example" )Add the publicgithub.comURLs for all your custom Golang code packages here.Note: The package name must bemain.The build process uses the package URL stated in the
deps.gofile to look for the package ongithub.comif the package is not found locally. Once the code package is pulled,deps.goinitializes the package.
Adding versioned dependencies to your custom extension
If your custom extension uses a third party library over which you have no control, you might want the extension to always use a specific version of the library. You can download the specific version of the library and place it under
<FLOGO_HOME>/lib/ext/src folder. You must not add an entry in the
deps.go file for dependency packages. Build the app binary.