Services
A service in Goa represents a collection of related methods that work together to provide specific functionality. Services help organize your API into logical groupings.
Service DSL
The Service DSL supports several options to configure and document your service:
var _ = Service("users", func() {
// Basic documentation
Description("User management service")
// Detailed documentation
Docs(func() {
Description("Detailed documentation for the user service")
URL("https://example.com/docs/users")
})
// Service-level error definitions
Error("unauthorized", String, "Authentication failed")
Error("not_found", NotFound, "Resource not found")
// Service-wide metadata
Meta("swagger:tag", "Users")
Meta("rpc:package", "usersvc")
// Security requirements
Security(OAuth2, func() {
Scope("read:users")
Scope("write:users")
})
// Service-level variables
Variable("version", String, func() {
Description("API version")
Default("v1")
Enum("v1", "v2")
})
// Methods
Method("create", func() {
// ... method definition
})
Method("list", func() {
// ... method definition
})
// Files served by the service
Files("/docs", "./swagger", func() {
Description("API documentation")
})
})
Service-Level Errors
Define errors that can be returned by all methods in the service: