Skip to content

Commit

Permalink
Merge pull request #56 from lsviben/init-hooks
Browse files Browse the repository at this point in the history
add init hooks
  • Loading branch information
phisco authored Jan 29, 2024
2 parents 108f4ee + e0dd990 commit e7de668
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To get started:

1. Replace `function-template-go` with your function in `go.mod`,
`package/crossplane.yaml`, and any Go imports. (You can also do this
automatically by running the `./init.sh <function-name>` script.)
2. Update `input/v1beta1/` to reflect your desired input (and run `go generate`)
3. Add your logic to `RunFunction` in `fn.go`
4. Add tests for your logic in `fn_test.go`
5. Update `README.md`, to be about your function!
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ To learn how to use this template:

If you just want to jump in and get started:

1. Replace `function-template-go` with your function's name in `go.mod`,
`package/crossplane.yaml`, and any Go imports
1. Replace `function-template-go` with your function in `go.mod`,
`package/crossplane.yaml`, and any Go imports. (You can also do this
automatically by running the `./init.sh <function-name>` script.)
1. Update `input/v1beta1/` to reflect your desired input (and run `go generate`)
1. Add your logic to `RunFunction` in `fn.go`
1. Add tests for your logic in `fn_test.go`
Expand Down
21 changes: 21 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# This script helps initialize a new function project by
# replacing all instances of function-template-go with the
# name of your function. The scripts accepts two arguments:
# 1. The name of your function
# 2. The path to your function directory

set -e

cd "$2" || return

# Replace function-template-go with the name of your function
# in go.mod
perl -pi -e s,function-template-go,"$1",g go.mod
# in fn.go
perl -pi -e s,function-template-go,"$1",g fn.go
# in examples
perl -pi -e s,function-template-go,"$1",g example/*

echo "Function $1 has been initialised successfully"

0 comments on commit e7de668

Please sign in to comment.