Write Cloud Functions bookmark_border Stay organized with collections Save and categorize content based on your preferences. Cloud Functions supports writing source code in a number of programming languages. The language runtime you choose and the type of function you want to write determine how to structure your code and implement your function. This page provides an overview of the types of Cloud Functions and expectations for source code. Types of Cloud Functions There are two types of Cloud Functions: **HTTP functions**, which handle HTTP requests and use [HTTP triggers](https://cloud.google.com/functions/docs/calling/http). See [Write HTTP functions](https://cloud.google.com/functions/docs/writing/write-http-functions) for information about implementing HTTP functions. **Event-driven functions**, which handle events from your cloud environment and use event triggers as described in [Cloud Functions triggers](https://cloud.google.com/functions/docs/calling). See [Write event-driven functions](https://cloud.google.com/functions/docs/writing/write-event-driven-functions) for information about implementing event-driven functions. Use an HTTP function when you need your function to have a URL endpoint and respond to HTTP requests, such as for webhooks. Use an event-driven function when your function should be triggered directly in response to events within your Google Cloud project, such as messages on a Pub/Sub topic or changes in a Cloud Storage bucket. Source directory structure In order for Cloud Functions to locate your function definition, each language runtime has requirements for structuring your source code. The basic directory structure for a function in each runtime is shown below. Node.js Python Go Java C# Ruby PHP The basic directory structure for Go functions is as follows: . ├── myfunction.go └── go.mod Your function must be in a Go package at the root of your project. The package and its source files can have any name, except your function cannot be in package main. If you need a main package, for example for local testing, you can create one in a subdirectory: . ├── myfunction.go ├── go.mod └── cmd/ └── main.go Your go.mod file must include the Functions Framework for Gohttps://github.com/GoogleCloudPlatform/functions-framework-go as a dependency: module example.com/my-modulerequire ( github.com/GoogleCloudPlatform/functions-framework-go v1.5.2) starNote: You can add the Functions Framework dependency by running go get github.com/GoogleCloudPlatform/functions-framework-go. The code in your root package must define your function entry point and can import other code from subpackages and dependencies as normal. Your package can also define multiple function entry points that can be deployed separately. starNote: For an example of setting up a basic Cloud Functions project in Go, see the Functions Framework for Go Quickstart on GitHubhttps://github.com/GoogleCloudPlatform/functions-framework-go#quickstart-hello-world-on-your-local-machine. If you are thinking of grouping multiple functions into a single project, be aware that every function may end up sharing the same set of dependencies. However, some of the functions may not need all of the dependencies. Where possible, we recommend splitting up large multi-function codebases and putting each function in its own top-level directory as shown above, with its own source and project configuration files. This approach minimizes the number of dependencies required for a particular function, which in turn reduces the amount of memory your function needs. Function entry point Your source code must define an entry point for your function, which is the particular code that is executed when the Cloud Function is invoked. You specify this entry point when you deploy your function. How you define the entry point depends on the language runtime you use. For some languages, the entry point is a function, whereas for others the entry point is a class. To learn more about defining entry points and implementing Cloud Functions in different languages, see Write HTTP functions and Write event-driven functions. Dependencies You can manage dependencies using standard tools for each runtime. For more information, see the appropriate page: Specifying dependencies in Node.js Specifying dependencies in Python Specifying dependencies in Go Specifying dependencies in Java Specifying dependencies in .NET Specifying dependencies in Ruby Specifying dependencies in PHP Next steps Learn how to write HTTP functions. Learn how to write event-driven functions. Learn about Cloud Functions triggers.