gogen

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 6 Imported by: 0

README

go

Go client code generator implementation.

Responsibility

Generates type-safe Go code from OpenFGA schemas, producing:

  • Object type constants (TypeUser, TypeRepository)
  • Relation constants (RelCanRead, RelOwner)
  • Constructor functions (User(id), Repository(id))
  • Wildcard constructors (AnyUser() for user:* patterns)

Architecture Role

internal/clientgen (registry)
       │
       └── internal/clientgen/go
               │
               └── Implements Generator interface

Registered via init(), discovered by the CLI through the registry.

Output

Single file schema_gen.go containing all generated code. The file imports the melange runtime for type definitions.

Design Decisions

  • Uses melange.Object and melange.Relation types from runtime
  • Pascal-cased type names, prefixed with Type and Rel
  • Supports relation filtering via prefix (e.g., only can_* relations)
  • Validates schema for cycles before generating

Documentation

Overview

Package gogen implements the Go client code generator for melange.

This generator produces type-safe Go code from authorization schemas, including object type constants, relation constants, and constructor functions.

Generated code uses the melange runtime (github.com/pthm/melange/melange) for type definitions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct{}

Generator implements clientgen.Generator for Go.

func (*Generator) DefaultConfig

func (g *Generator) DefaultConfig() *clientgen.Config

DefaultConfig returns default configuration for Go code generation.

func (*Generator) Generate

func (g *Generator) Generate(types []schema.TypeDefinition, cfg *clientgen.Config) (map[string][]byte, error)

Generate produces Go client code from the given type definitions.

Returns a single file map entry with key "schema_gen.go".

Generated code includes:

  • ObjectType constants (TypeUser, TypeRepository, etc.)
  • Relation constants (RelCanRead, RelOwner, etc.)
  • Constructor functions (User(id), Repository(id), etc.)
  • Wildcard constructors (AnyUser(), AnyRepository(), etc.)

func (*Generator) Name

func (g *Generator) Name() string

Name returns "go" as the runtime identifier.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL