diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-03-02 22:02:59 -0500 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-03-02 22:03:58 -0500 |
| commit | 590a15a0c3658abf13db39bd3c52021a7ec6ba82 (patch) | |
| tree | c9db32f7e5da32f0f1a09bd26e096b7963ca2477 /valid/example_test.go | |
| parent | 7854f16ef4071ef3bd2f7574a45462f53291a4be (diff) | |
| download | x-590a15a0c3658abf13db39bd3c52021a7ec6ba82.tar.xz x-590a15a0c3658abf13db39bd3c52021a7ec6ba82.zip | |
web/ollama: add Hallucinate function
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'valid/example_test.go')
| -rw-r--r-- | valid/example_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/valid/example_test.go b/valid/example_test.go new file mode 100644 index 0000000..e321ad9 --- /dev/null +++ b/valid/example_test.go @@ -0,0 +1,39 @@ +package valid + +import ( + "errors" + "log/slog" +) + +type Example struct { + Name string +} + +func (e *Example) Valid() error { + var errs []error + if e.Name == "" { + errs = append(errs, errors.New("name is empty")) + } + if len(errs) == 0 { + return nil + } + return errors.Join(errs...) +} + +func ExampleValider_Valid() { + e := Example{Name: ""} + + if err := e.Valid(); err != nil { + slog.Error("validation failed", "err", err) + } + + // Output: + // validation failed err=name is empty + + e.Name = "ollama" + if err := e.Valid(); err != nil { + slog.Error("validation failed", "err", err) + } + // Output: + // +} |
