Apps are the top-level organizational unit in Modal. They contain Functions, Classes, and other resources.
Referencing apps
FromName
References an App by its name, optionally creating it if it doesn’t exist.
app, err := mc.Apps.FromName(ctx, "my-app", &modal.AppFromNameParams{
CreateIfMissing: true,
})
if err != nil {
// Handle error
}
Context for the operation
Optional parametersEnvironment name (e.g., “main”, “dev”). Defaults to client’s environment.
If true, creates the App if it doesn’t exist. Defaults to false.
Returns:
*App - The App instance
error - NotFoundError if the App doesn’t exist and CreateIfMissing is false
App type
The App type represents a deployed Modal App.
The unique identifier for the App
Example usage
package main
import (
"context"
"fmt"
"github.com/modal-labs/modal-client/go"
)
func main() {
ctx := context.Background()
mc, _ := modal.NewClient()
defer mc.Close()
// Reference an existing App
app, err := mc.Apps.FromName(ctx, "my-app", nil)
if err != nil {
fmt.Printf("App not found: %v\n", err)
return
}
fmt.Printf("App ID: %s\n", app.AppID)
fmt.Printf("App Name: %s\n", app.Name)
// Create an App if it doesn't exist
app2, _ := mc.Apps.FromName(ctx, "new-app", &modal.AppFromNameParams{
CreateIfMissing: true,
})
fmt.Printf("Created/Retrieved App: %s\n", app2.AppID)
}