Project Standard
Two minimal requrements:
- packages directory
- project.yml
packages directory standard
The directory specification of packages is the same as the directory specification of your Function, for example, I created this Function:
Figure 1:An Digital Ocean Function Creation |
---|
那么对应的 package 目录就为:
[root@liqiang.io]# tree
.
├── packages
│ └── test-package
│ └── functiona
│ └── main.go
└── project.yml
The packages directory is allowed to contain multiple Functions, so just follow this standard.
project.yml standard
Here is a straightforward project configuration file with all the properties.
parameters:
param1: value
environment:
env1: value
packages:
- name: package1
parameters: {}
environment: {}
annotations: {}
actions:
- name: function1
parameters: {}
environment: {}
limits: {}
runtime: 'go:default'
main: ''
You can see that the overall structure is three-tiered.
- The first level: the project level, where a project contains multiple packages, and the properties defined at the project level are inherited by the packages.
- The second level: package level, where a package contains multiple functions, and the properties defined at the package level will also be inherited by functions (including, of course, properties inherited from the project).
- The third level: the function level, which defines special properties belonging to this function.
generic functions
As you can see, all three levels have parameters and environment as parameters.
parameters
The properties defined in parameters are passed to Function as parameters, for example, the entry interface of Function is as follows.
func Main(args map[string]interface{}) map[string]interface{} {
Then these defined arguments are all part of args.
environment
This is the clichéd environment variable, so I won’t go into it.
Function Parameters
main
The main
parameter defines the entry point of Function. You may wonder why you need to customize it when the entry point is Main
. It’s actually quite simple, Main
is the default entry, if you don’t define it, then use it, if you need to customize it, you can define it with the main
parameter.
runtime
runtime
is used to define the application runtime, for example, I use go, so I define go as the runtime, but go has different versions, so you can specify the version of go, the default is go:default
, specify the version is similar to: go:1.18
.
limits
The limits
field is used to limit some properties of the Function, the following properties are currently supported.
timeout
: unit: ms, used to limit the response time of the API.memory
: unit: MB, used to limit the memory used by the program.logs
: unit: KB, used to limit the size of the program’s logs.
Some lessons learned
- Function code can only be in a single directory
- My guess: Function is positioned as a
function
, not aproject
, so it shouldn’t be very large, and a single-level directory will satisfy the requirement - My guess: Function is a business unit, and when you need to build a more complex structure in layers, you need to combine different Functions to complete it.
- My guess: Function is positioned as a
- The feeling is that Digital Ocean’s Function is really young, and the first public function is still very limited, but I know that there are definitely not only so many supported, but in fact there are only so many that I can know how to use.
- For example, the app-spec.yaml in this example project: https://github.com/digitalocean/sample-functions-golang-random does not explain how to use it.
- There is also no explanation of how a Go project should work if it imports another package, for example.