webhookvalidator

package
v0.0.0-...-a5b5e9b Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NaisCompare

func NaisCompare(new, old interface{}, path *field.Path) error
Example
package main

import (
	"fmt"

	"github.com/nais/liberator/pkg/webhookvalidator"
	"k8s.io/apimachinery/pkg/util/validation/field"
)

func main() {
	type Pet struct {
		// +nais:doc:Immutable=true
		Name string `nais:"key"`
		// +nais:doc:Immutable=true
		Species string `nais:"immutable"`
	}

	type Pets struct {
		Pets []Pet
	}

	new := Pets{
		Pets: []Pet{
			{Name: "Alberto", Species: "Dog"},
			{Name: "Sansa", Species: "Bird"},
		},
	}
	old := Pets{
		Pets: []Pet{
			{Name: "Alberto", Species: "Dog"},
			{Name: "Sansa", Species: "Cat"},
		},
	}

	err := webhookvalidator.NaisCompare(new, old, field.NewPath("animals"))
	fmt.Println(err)
}
Output:

animals.Pets.1.Species: Invalid value: "Bird": field is immutable

Types

This section is empty.

Jump to

Keyboard shortcuts

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