Skip to main content

Visibility

A module's private fields will not be persisted.

Here's an example of a Dagger Module that has multiple properties which are not exposed outside the module, and a Dagger Function that uses the crypto library to hash these:

package main

import (
"crypto/sha256"
"fmt"
)

type Person struct {
Name string
Job string

// +private
Age int
}

func New(name string, job string, age int) *Person {
return &Person{
Name: name,
Job: job,
Age: age,
}
}

// Get the identity of the person based on its personal information.
func (p *Person) Identity() string {
str := fmt.Sprintf("%s-%s-%d", p.Name, p.Job, p.Age)
return fmt.Sprintf("%x", sha256.Sum256([]byte(str)))
}

From dagger functions, it can be seen that age and job are not exposed:

dagger functions
Name Description
identity Get the identity of the person based on its personal information.
name Get the name of the person

Here is an example call for this module:

dagger call --name="john" --age=23 --job="devops" identity

The result will be:

c11fb2dc1c5bfe34b0ed5737b8c58914ddb56a83602ead3eff2f06e46efc4a24