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

Note: Once the custom Golang code is placed in the <FLOGO_HOME>/lib/ext/src folder, it will be a part of all apps built from that environment.
Note: Using custom Golang code is not supported in TIBCO Cloud™ Integration - Flogo®.
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/src directory

    Or

  • Add the package to deps.go
To incorporate it into your build environment, do the following:
  1. Pull the package from the Git repository ahead of time. This is not required if you want the package pulled dynamically during build time.
    1. Pull the package from the external Git repository (github.com) to your local environment.
    2. Place the package in <FLOGO_HOME>/lib/ext/src folder.
    3. Copy any dependent Golang packages required by your custom code into <FLOGO_HOME>/lib/ext/src folder.
      Note: Skipping this step will pull the latest versions of the dependencies at build time.
  2. Create a deps.go file under <FLOGO_HOME>/lib/ext/src folder 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.go file content:
    package main
    
    
    import _ "github.com/<username>/contrib/eventlistener"
    package main
    
    import (
        _ "github.com/<username>/contrib/eventlistener"
        _ "github.com/<username>/contrib/example"
    )
    Add the public github.com URLs for all your custom Golang code packages here.
    Note: The package name must be main.

    The build process uses the package URL stated in the deps.go file to look for the package on github.com if the package is not found locally. Once the code package is pulled, deps.go initializes 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.