### Golang Dependency Management Example Source: https://github.com/knative/func/blob/main/docs/function-templates/golang.md Example command to add a new dependency to a Golang project using 'go get'. ```console go get gopkg.in/yaml.v2@v2.4.0 ``` -------------------------------- ### List Repositories Source: https://github.com/knative/func/blob/main/docs/reference/func_repository_list.md Use this command to list all installed template repositories. No setup or imports are required. ```bash func repository list ``` -------------------------------- ### Example Podman Service Configuration Source: https://github.com/knative/func/blob/main/docs/building-functions/podman.md This is an example of how to configure the Podman service to include the --time=0 flag, which can resolve build issues. ```bash ExecStart=/usr/bin/podman $LOGGING system service --time=0 ``` -------------------------------- ### Setup Git Hooks Source: https://github.com/knative/func/blob/main/CONTRIBUTING.md Installs git hooks to perform basic pre-commit checks. Run this command to ensure code quality before committing. ```shell make setup-githooks ``` -------------------------------- ### Install Node.js Function Dependencies Source: https://github.com/knative/func/blob/main/docs/function-templates/nodejs.md Install the necessary dependencies for your Node.js function, including testing frameworks, using 'npm install'. This is a standard Node.js project setup step. ```bash ❯ npm install ``` -------------------------------- ### Python Function Unit Testing Setup Source: https://github.com/knative/func/blob/main/docs/function-templates/python.md Commands for setting up a virtual environment, installing dependencies, and running unit tests for a Python function using pytest. ```bash # Create a virtual environment (Python 3.3+) python3 -m venv venv # Activate the virtual environment # On Linux/macOS: source venv/bin/activate # On Windows: # venv\Scripts\activate # Upgrade pip to ensure you have the latest version python -m pip install --upgrade pip # Install the function package and its dependencies (including test dependencies) pip install -e . # Run tests with pytest pytest # Run tests with verbose output pytest -v # Run tests with coverage (requires pytest-cov) pip install pytest-cov pytest --cov=function --cov-report=term-missing ``` -------------------------------- ### Start Podman Service on Linux Source: https://github.com/knative/func/blob/main/docs/building-functions/podman.md On older versions of `func` on Linux, start the Podman service to enable the Docker API on a UNIX socket. This is required for `func` to communicate with Podman. ```bash ❯ systemctl start --user podman.socket ``` -------------------------------- ### Start MCP Server Source: https://github.com/knative/func/blob/main/docs/reference/func_mcp_start.md Use this command to start the Model Context Protocol (MCP) server. This command is intended for use by MCP clients and should not be run directly. ```bash func mcp start ``` -------------------------------- ### List all repositories Source: https://github.com/knative/func/blob/main/docs/reference/func_repository.md List all available repositories, including the default one. Use the --verbose flag to see the URL from which remote repositories were installed. ```bash func repository list ``` ```bash func repository list -v ``` -------------------------------- ### VS Code MCP Server Configuration Example Source: https://github.com/knative/func/blob/main/docs/mcp-integration/integration.md Example of how to integrate the base MCP server configuration into VS Code's `settings.json` file. This allows VS Code to manage the MCP server. ```json { // other VS Code settings... "mcpServers": { "func-mcp": { "command": "func", "args": ["mcp", "start"] } } } ``` -------------------------------- ### List local KinD development clusters Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster_list.md Use this command to view all local KinD clusters configured for Knative func development. No setup is required beyond having the func CLI installed. ```bash func cluster list ``` -------------------------------- ### Local Execution Commands Source: https://github.com/knative/func/blob/main/templates/typescript/http/README.md Commands to install dependencies, build, and run the function locally. ```console npm install npm run build npm run local ``` -------------------------------- ### Run a Go Function Locally Source: https://github.com/knative/func/blob/main/docs/function-templates/golang.md After building, use `func run` to start your function locally. It will be accessible via HTTP requests, typically at http://localhost:8080. ```bash ❯ func run ``` -------------------------------- ### List Functions Source: https://github.com/knative/func/blob/main/docs/reference/func_list.md Lists all functions in the current namespace. Use this command to get a quick overview of deployed functions. ```bash func list ``` -------------------------------- ### Container Registry Authentication Prompt Source: https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md Example output showing the prompt for credentials when deploying a function to a remote container registry. You will be asked for server, username, and password. ```bash $ kn func deploy --remote 🕕 Creating Pipeline resources Please provide credentials for image registry used by Pipeline. ? Server: https://index.docker.io/v1/ ? Username: my-repo ? Password: ******** Function deployed at URL: http://test-function.default.svc.cluster.local ``` -------------------------------- ### Add a new repository Source: https://github.com/knative/func/blob/main/docs/reference/func_repository.md Add a new repository to the installed set by providing a name and URL. This allows using templates from the added repository by prefixing the template name with the repository name. ```bash func repository add boson https://github.com/boson-project/templates ``` -------------------------------- ### List Available Language Runtimes Source: https://github.com/knative/func/blob/main/docs/reference/func_languages.md Use this command to see all language runtimes that are currently available, including embedded and installed ones. This provides a general overview of supported languages. ```bash func languages ``` -------------------------------- ### Language Pack Directory Structure Example Source: https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md Illustrates a typical directory structure for a Ruby language pack with templates for CloudEvent and HTTP function signatures. ```yaml root ├── ruby | ├── cloudevent | │   ├── func.rb | | ├── manifest.yaml | │   ├── Gemfile | │   ├── Rakefile | │   └── README.md | ├── http | │   ├── func.rb | | ├── manifest.yaml | │   ├── Gemfile | │   ├── Rakefile | │   └── README.md | └── manifest.yaml └── manifest.yaml ``` -------------------------------- ### List Templates for a Specific Language Source: https://github.com/knative/func/blob/main/docs/reference/func_templates.md To view templates for a particular language runtime, specify the language name as an argument. For example, 'go' for Go templates. ```bash $ func templates go ``` -------------------------------- ### Python Function Initialization Source: https://github.com/knative/func/blob/main/docs/function-templates/python.md The `start` method is called when a function instance begins execution, receiving configuration as a dictionary. It initializes a debug flag based on the 'DEBUG' configuration. ```python def start(self, cfg): """Initialize function with configuration.""" self.debug = cfg.get('DEBUG', 'false').lower() == 'true' logging.info("Function initialized") ``` -------------------------------- ### Run Function Locally with Host Builder Source: https://github.com/knative/func/blob/main/templates/python/cloudevents/README.md Use `func run` to test your Function locally before deployment. For development environments where Python is installed, it's suggested to use the `host` builder. ```bash # Run function on the host (outsdie of a container) func run --builder=host ``` -------------------------------- ### Create function using a template from a remote repository directly Source: https://github.com/knative/func/blob/main/docs/reference/func_repository.md Use the --repository flag on the 'create' command to use a template from a remote repository directly without installing it locally. This leaves the local disk untouched. ```bash func create -l go \ --template hello-world \ --repository https://github.com/boson-project/templates ``` -------------------------------- ### Configure Podman Machine for macOS/Windows Source: https://github.com/knative/func/blob/main/docs/building-functions/podman.md For macOS and Windows, Podman Desktop is recommended. Ensure Podman machine is running in rootful mode and note the API socket path provided after starting the machine. ```bash You can still connect Docker API clients by setting DOCKER_HOST using the following command in your terminal session: export DOCKER_HOST='unix:///Users/jdoe/.local/share/containers/podman/machine/podman-machine-default/podman.sock' ``` -------------------------------- ### Run All Build and Development Tasks Source: https://github.com/knative/func/blob/main/AGENTS.md Execute this command to build the binary and regenerate documentation. It encompasses all necessary build and development tasks. ```bash make all ``` -------------------------------- ### Create a minimal cluster Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster_create.md Set up a basic cluster containing only Kubernetes and a local registry, excluding Knative Serving and Eventing. ```bash func cluster create --serving=false --eventing=false ``` -------------------------------- ### Create Function with External Language Pack Template Source: https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md Shows how to create a new function using a specific template from an added external language pack. This example uses a Node.js CloudEvents template from the 'functastic' repository. ```bash ❯ func create -l node -t functastic/events # create a Node.js CloudEvents template from the now-local functastic repo ``` -------------------------------- ### Rename an installed repository Source: https://github.com/knative/func/blob/main/docs/reference/func_repository.md Rename a previously installed repository from an old name to a new name. Only installed repositories can be renamed. ```bash func repository rename boson functastic ``` -------------------------------- ### Create and Deploy Function with Client Library Source: https://github.com/knative/func/blob/main/docs/integrators_guide.md Use this client to create a function using buildpacks, push to a registry, and deploy to Knative. Configure the client with specific builders, pushers, deployers, and registries. ```go package main import ( fn "github.com/knative/func" "github.com/knative/func/buildpacks" "github.com/knative/func/docker" "github.com/knative/func/knative" "log" ) func main() { pusher, err := docker.NewPusher() if err != nil { log.Fatal(err) } deployer, err := knative.NewDeployer("") if err != nil { log.Fatal(err) } // A client which uses embedded function templates, // Quay.io/alice for interstitial build artifacts. // Docker to build and push, and a Knative client for deployment. client := fn.New( fn.WithBuilder(buildpacks.NewBuilder()), fn.WithPusher(pusher), fn.WithDeployer(deployer), fn.WithRegistry("quay.io/alice")) // Create a Go function which listens for CloudEvents. // Publicly routable as https://www.example.com. // Local implementation is written to the current working directory. funcTest := fn.Function{ Runtime: "go", Name: "my-function", Image: "quay.io/alice/my-function", Root: "my-function", } if err := client.Create(funcTest); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Install Tekton Pipelines Source: https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md Installs Tekton Pipelines using a specific release version. Ensure Tekton Pipelines is installed on your cluster before proceeding. ```bash kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v1.6.0/release.yaml ``` -------------------------------- ### func CLI help options Source: https://github.com/knative/func/blob/main/docs/reference/func.md Displays the available help options for the func CLI. ```bash -h, --help help for func ``` -------------------------------- ### Send GET Request Source: https://github.com/knative/func/blob/main/docs/reference/func_invoke.md Specifically sends a GET request to the function by setting the --request-type flag. ```bash $ func invoke --request-type=GET ``` -------------------------------- ### List Repositories Options Source: https://github.com/knative/func/blob/main/docs/reference/func_repository_list.md These are the available options for the 'func repository list' command. Use '-c' or '--confirm' to prompt for interactive confirmation, '-h' or '--help' for help, and '-v' or '--verbose' to print verbose logs. ```bash -c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM) -h, --help help for list -v, --verbose Print verbose logs ($FUNC_VERBOSE) ``` -------------------------------- ### Local Function Execution Example Source: https://github.com/knative/func/blob/main/templates/node/cloudevents/README.md This example demonstrates how to send a Cloud Event to the locally running function using curl. ```APIDOC ## POST / ### Description Endpoint for your function to receive Cloud Events. ### Method POST ### Endpoint / ### Request Body - **(object)** - The Cloud Event payload. ### Request Example ```console curl -X POST -d '{"name": "Tiger", "customerId": "0123456789"}' \ -H'Content-type: application/json' \ -H'Ce-id: 1' \ -H'Ce-source: cloud-event-example' \ -H'Ce-type: dev.knative.example' \ -H'Ce-specversion: 1.0' \ http://localhost:8080 ``` ``` -------------------------------- ### Deploy function with interactive prompts Source: https://github.com/knative/func/blob/main/docs/reference/func_deploy.md Use interactive prompts for the first deployment. Settings are remembered for future deployments. ```bash func deploy -c ``` -------------------------------- ### Install Dependency with npm Source: https://github.com/knative/func/blob/main/docs/function-templates/nodejs.md Use npm to install additional dependencies for your Node.js function. These will be included in the final deployment container image. ```bash npm install --save opossum ``` -------------------------------- ### Help for func cluster list Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster_list.md Displays help information for the 'func cluster list' command, including available options. ```bash func cluster list --help ``` -------------------------------- ### Create a fully configured development cluster Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster.md Use this command to create a development cluster with all default components pre-installed. ```bash func cluster create ``` -------------------------------- ### Simple GET Request with go-retryablehttp Source: https://github.com/knative/func/blob/main/third_party/VENDOR-LICENSE/github.com/hashicorp/go-retryablehttp/README.md Demonstrates a basic GET request using the retryablehttp client. The call will automatically retry on failure with exponential backoff. ```go resp, err := retryablehttp.Get("/foo") if err != nil { panic(err) } ``` -------------------------------- ### Curl POST Request Example Source: https://github.com/knative/func/blob/main/templates/node/http/README.md Example of using curl to send a POST request with a JSON body and content-type header to a local HTTP function endpoint. ```bash curl -X POST -d '{"hello": "world"}' \ -H'Content-type: application/json' \ http://localhost:8080 ``` -------------------------------- ### Create a Go Function Project Source: https://github.com/knative/func/blob/main/docs/function-templates/golang.md Use the `func create` command with the `-l go` flag to generate a new Go function project. This sets up the basic directory structure and necessary files. ```bash ❯ func create -l go fn Project path: /home/developer/projects/fn Function name: fn Runtime: go ❯ tree fn ├── README.md ├── func.yaml ├── go.mod ├── go.sum ├── function.go └── function_test.go ``` -------------------------------- ### Invoke Functions::withBeans with Simple HTTP GET Source: https://github.com/knative/func/blob/main/docs/function-templates/quarkus.md Invoke the `Functions::withBeans` function using an HTTP GET request with query parameters. The parameter name should match the input bean's field. ```shell curl "http://localhost:8080?message=Hello%20there." -X GET ``` -------------------------------- ### Distributing and Creating Functions with Language Packs Source: https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md Demonstrates how to add a language pack repository and create a new function using a specific template from that repository. ```bash func repository add func https://github.com/knative-extensions/func-tastic func create -l go -t func/hello-world ``` -------------------------------- ### List All Available Templates Source: https://github.com/knative/func/blob/main/docs/reference/func_templates.md Use this command to see all available function templates, grouped by language runtime. No additional arguments are needed. ```bash $ func templates ``` -------------------------------- ### Uninstall Tekton Pipelines Source: https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md Removes Tekton Pipelines resources from the cluster. This command uninstalls the Tekton Pipelines installation. ```bash kubectl delete -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml ``` -------------------------------- ### Create a Node.js Function Project Source: https://github.com/knative/func/blob/main/docs/function-templates/nodejs.md Use the 'func create' command to initialize a new Node.js function project. This command sets up the basic directory structure and necessary configuration files. ```bash ❯ func create -l node fn Project path: /home/developer/projects/fn Function name: fn Runtime: node ❯ tree fn fn ├── func.yaml ├── index.js ├── package.json ├── README.md └── test ├── integration.js └── unit.js ``` -------------------------------- ### Get Deployed Function URL Source: https://github.com/knative/func/blob/main/docs/function-templates/golang.md After deployment, use the `func info` command to retrieve the URL of your deployed function. ```bash ❯ func info ``` -------------------------------- ### Build Binary for Current OS Source: https://github.com/knative/func/blob/main/AGENTS.md Use this command to build the binary specifically for your current operating system. It's a focused build command. ```bash make build ``` -------------------------------- ### Handle CloudEvent in TypeScript Source: https://github.com/knative/func/blob/main/docs/function-templates/typescript.md This is an example of a function that expects to receive a CloudEvent with customer data and returns a processed event. ```typescript import { Context, CloudEvent } from "@google-cloud/functions-framework"; // Expects to receive a CloudEvent with customer data function handle(context: Context, cloudevent?: CloudEvent): CloudEvent { // process the customer const customer = cloudevent.data; const processed = processCustomer(customer); return context.cloudEventResponse(customer) .source('/customer/process') .type('customer.processed') .response(); } ``` -------------------------------- ### HCL Array Example Source: https://github.com/knative/func/blob/main/third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/README.md Shows how to define an array in HCL. Arrays can contain a mix of primitive types, other arrays, and objects. ```hcl ["foo", "bar", 42] ``` -------------------------------- ### Basic func build command Source: https://github.com/knative/func/blob/main/docs/reference/func_build.md This is the basic command to initiate the build process for a function container. ```bash func build ``` -------------------------------- ### Send POST Request to Rust Function Source: https://github.com/knative/func/blob/main/templates/rust/http/README.md Example using `curl` to send a JSON payload to the locally running function. ```console curl -d '{"hello": "world"}' \ -H'content-type: application/json' \ http://localhost:8080 ``` -------------------------------- ### Add Repository Options Source: https://github.com/knative/func/blob/main/docs/reference/func_repository_add.md These are the available options for the 'func repository add' command. Use '--confirm' for interactive confirmation or '--verbose' for detailed logs. ```bash -c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM) ``` ```bash -h, --help help for add ``` ```bash -v, --verbose Print verbose logs ($FUNC_VERBOSE) ``` -------------------------------- ### Access Request Headers Source: https://github.com/knative/func/blob/main/docs/function-templates/typescript.md Access HTTP request headers using the `context.headers` object. This example logs the value of a 'custom-header'. ```typescript function handle(context: Context): string { context.log.info(context.headers['custom-header']); return 'OK'; } ``` -------------------------------- ### Run and Invoke Locally Source: https://github.com/knative/func/blob/main/docs/reference/func_invoke.md Starts a function locally using 'func run' and then invokes it with a test request in a separate terminal. ```bash $ func run $ func invoke ``` -------------------------------- ### Configure Python Function from Environment Source: https://github.com/knative/func/blob/main/docs/function-templates/python.md Illustrates how to configure a Python function using environment variables for settings like API keys, cache TTL, and log levels. Ensure logging is configured appropriately. ```python class Function: def start(self, cfg): """Configure function from environment.""" self.api_key = cfg.get('API_KEY') self.cache_ttl = int(cfg.get('CACHE_TTL', '300')) self.log_level = cfg.get('LOG_LEVEL', 'INFO') logging.basicConfig(level=self.log_level) ``` -------------------------------- ### func repository rename Source: https://github.com/knative/func/blob/main/docs/reference/func_repository_rename.md Renames an installed template repository. It takes the old repository name and the new repository name as arguments. ```APIDOC ## func repository rename Rename a repository ``` func repository rename ``` ### Parameters * **old** (string) - Required - The current name of the repository. * **new** (string) - Required - The new name for the repository. ### Options * **-c, --confirm** (bool) - Optional - Prompt to confirm options interactively ($FUNC_CONFIRM). * **-h, --help** (bool) - Optional - help for rename. * **-v, --verbose** (bool) - Optional - Print verbose logs ($FUNC_VERBOSE). ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/knative/func/blob/main/AGENTS.md Execute end-to-end tests, which require a cluster. This is for significant architectural changes and requires reading 'CONTRIBUTING.md' for setup. ```bash make test-full ``` -------------------------------- ### Typical Command Pattern in Knative Function CLI Source: https://github.com/knative/func/blob/main/ARCHITECTURE.md Illustrates the standard pattern for commands within the CLI, showing client initialization with a builder and subsequent build operation. This pattern is used across various commands to interact with the function building process. ```go client, _ := fn.New(fn.WithBuilder(buildpacks.NewBuilder())) client.Build(ctx, f) ``` -------------------------------- ### Run Core Unit Tests Source: https://github.com/knative/func/blob/main/AGENTS.md Execute core unit tests for Go files. This is a fundamental step before committing changes. ```bash make test ``` -------------------------------- ### HCL Object and Nested Object Example Source: https://github.com/knative/func/blob/main/third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/README.md Demonstrates the syntax for defining objects and nested objects in HCL. This structure is directly translatable to JSON. ```hcl variable "ami" { description = "the AMI to use" } ``` -------------------------------- ### JSON Representation of Purchase Data Source: https://github.com/knative/func/blob/main/docs/function-templates/quarkus.md Example JSON structure for the `Purchase` data, expected for function invocation via HTTP POST or CloudEvent. ```json { "customerId": "0123456", "productId": "6543210" } ``` -------------------------------- ### Retrieve Deployed Service URL Source: https://github.com/knative/func/blob/main/templates/rust/http/README.md Use `func info -o url` to get the URL of your deployed Knative Service, then use `curl` to access it. ```console curl $(func info -o url) ``` -------------------------------- ### Deploy the function Source: https://github.com/knative/func/blob/main/docs/reference/func_deploy.md This is the basic command to deploy the function in the current working directory. ```bash func deploy ``` -------------------------------- ### Build a Go Function Source: https://github.com/knative/func/blob/main/docs/function-templates/golang.md Before running or deploying, build your Go function using the `func build` command. This creates an OCI container image. ```bash ❯ func build ``` -------------------------------- ### Help for Volumes Command Source: https://github.com/knative/func/blob/main/docs/reference/func_config_volumes.md Access help information for the 'func config volumes' command to understand all available options and their usage. ```bash func config volumes --help ``` -------------------------------- ### Accessing Request Headers Source: https://github.com/knative/func/blob/main/docs/function-templates/nodejs.md HTTP request headers are available as an object via `context.headers`. The example shows how to access a custom header named 'x-custom-header'. ```javascript Function handle(context) { context.log.info(context.headers[custom-header]); } ``` -------------------------------- ### Create a cluster with a custom name and domain Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster_create.md Customize your development cluster by specifying a unique name and a custom DNS domain for services. ```bash func cluster create --name myproject --domain example.local ``` -------------------------------- ### Access Query Parameters Source: https://github.com/knative/func/blob/main/docs/function-templates/typescript.md Access query string parameters using `context.query` or directly from the context object. This example logs the 'name' query parameter. ```typescript function handle(context: Context): string { // Log the 'name' query parameter context.log.info(context.query.name); // Query parameters also are attached to the context context.log.info(context.name); return 'OK'; } ``` -------------------------------- ### Initialize Git Repository for Function Source: https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md Sets up a local Git repository for your function's source code and adds a remote origin. This is necessary for tracking changes and pushing to a remote repository. ```bash cd my-function git init git branch -M main git remote add origin git@github.com:my-repo/my-function.git ``` -------------------------------- ### Print Function Version in JSON Format Source: https://github.com/knative/func/blob/main/docs/reference/func_version.md Specify the output format as JSON using the --output json flag to get structured version information. ```bash func version --output json ``` -------------------------------- ### RBAC Permissions for All Deployers Source: https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md Sets up necessary RBAC permissions for the 'default' Service Account to deploy Functions using all deployers (Knative, raw, and Keda). Replace with your target namespace. ```bash export NAMESPACE= kubectl create role func-deployer \ --verb=get,list,create,update,delete \ --resource=deployments.apps,replicasets.apps,pods,services,httpscaledobjects.http.keda.sh \ --namespace=$NAMESPACE kubectl create rolebinding func-deployer-binding \ --role=func-deployer \ --serviceaccount=$NAMESPACE:default \ --namespace=$NAMESPACE kubectl create clusterrolebinding $NAMESPACE:knative-eventing-namespaced-admin \ --clusterrole=knative-eventing-namespaced-admin \ --serviceaccount=$NAMESPACE:default kubectl create clusterrolebinding $NAMESPACE:knative-serving-namespaced-admin \ --clusterrole=knative-serving-namespaced-admin \ --serviceaccount=$NAMESPACE:default ``` -------------------------------- ### JSON Equivalent of HCL Object Source: https://github.com/knative/func/blob/main/third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/README.md Provides the JSON representation for the preceding HCL object example, highlighting the direct mapping between HCL's structure and JSON. ```json { "variable": { "ami": { "description": "the AMI to use" } } } ``` -------------------------------- ### Run Function Tests Source: https://github.com/knative/func/blob/main/docs/function-templates/typescript.md Execute the unit and integration tests for your function using `npm test`. The default test framework is `tape`. ```bash npm test ``` -------------------------------- ### Add and List External Language Packs Source: https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md Demonstrates how to add an external language pack repository and list the available repositories. This allows developers to use templates from different sources. ```bash ❯ func repository add https://github.com/knative-extensions/func-tastic functastic # Add the func-tastic repo to the local environment ❯ func repo list # list repos default functastic ``` -------------------------------- ### Use Context Logger Source: https://github.com/knative/func/blob/main/docs/function-templates/typescript.md Utilize the `context.log` object to write output to cluster logs, adhering to the Pino logging API. This example logs an informational message. ```typescript function handle(context:Context): string { context.log.info('Processing customer'); return 'OK'; } ``` -------------------------------- ### Initiate interactive volume removal Source: https://github.com/knative/func/blob/main/docs/reference/func_config_volumes_remove.md Run this command without flags to start an interactive prompt for removing volume mounts from the function project in the current directory. ```bash func config volumes remove ``` -------------------------------- ### Handle CloudEvents in Python Source: https://github.com/knative/func/blob/main/docs/function-templates/python.md Provides a basic structure for handling CloudEvents by parsing headers like 'ce-type' and 'ce-source'. This is the starting point for processing event-driven data. ```python async def handle(self, scope, receive, send): """Handle CloudEvents.""" headers = dict(scope['headers']) # Check if this is a CloudEvent if b'ce-type' in headers: event_type = headers[b'ce-type'].decode() event_source = headers[b'ce-source'].decode() # Process CloudEvent... ``` -------------------------------- ### Add a Repository Source: https://github.com/knative/func/blob/main/docs/reference/func_repository_add.md Use this command to add a new repository for function templates. Provide a unique name and the URL of the repository. ```bash func repository add ``` -------------------------------- ### Help for cluster command Source: https://github.com/knative/func/blob/main/docs/reference/func_cluster.md Displays help information for the cluster command and its options. ```bash func cluster --help ``` -------------------------------- ### Remove an installed repository Source: https://github.com/knative/func/blob/main/docs/reference/func_repository.md Remove a repository by its name. This action removes the repository from local storage entirely. Use with caution, especially if using an altered repositories location. ```bash func repository remove functastic ``` -------------------------------- ### List Language Runtimes in JSON Format Source: https://github.com/knative/func/blob/main/docs/reference/func_languages.md To get a machine-readable output of available language runtimes, use the --json flag. This is useful for scripting or integrating with other tools. ```bash func languages --json ``` -------------------------------- ### List Configured Volumes with Verbose Logging Source: https://github.com/knative/func/blob/main/docs/reference/func_config_volumes.md Enable verbose logging with the --verbose flag to get more detailed output during the volume listing process. This can aid in debugging. ```bash func config volumes --verbose ``` -------------------------------- ### HCL List of Objects Example Source: https://github.com/knative/func/blob/main/third_party/VENDOR-LICENSE/github.com/hashicorp/hcl/README.md Illustrates an alternative way to define lists of objects in HCL using repeated blocks with the same identifier. This is equivalent to an array of objects in JSON. ```hcl service { key = "value" } service { key = "value" } ``` -------------------------------- ### Completion Command Options Source: https://github.com/knative/func/blob/main/docs/reference/func_completion.md The `completion` command supports a help flag to display available options. ```cli -h, --help help for completion ``` -------------------------------- ### Return CloudEvent from Node.js Function Source: https://github.com/knative/func/blob/main/docs/function-templates/nodejs.md A Node.js function can process incoming event data and return a new CloudEvent. This example demonstrates returning a processed customer event. ```javascript function handle(context, event) { return processCustomer(event.data) } function processCustomer(customer) { // process customer and return a new CloudEvent return new CloudEvent({ source: 'customer.processor', type: 'customer.processed' }) } ```