ollama source for Momentry Core verification

This commit is contained in:
Accusys
2026-05-22 17:19:10 +08:00
commit 0b31ff9135
2020 changed files with 1413145 additions and 0 deletions

28
app/types/not/found.go Normal file
View File

@@ -0,0 +1,28 @@
//go:build windows || darwin
package not
import (
"errors"
)
// Found is an error that indicates that a value was not found. It
// may be used by low-level packages to signal to higher-level
// packages that a value was not found.
//
// It exists to avoid using errors.New("not found") in multiple
// packages to mean the same thing.
//
// Found should not be used directly. Instead it should be wrapped
// or joined using errors.Join or fmt.Errorf, etc.
//
// Errors wrapping Found should provide additional context, e.g.
// fmt.Errorf("%w: %s", not.Found, key)
//
//lint:ignore ST1012 This is a sentinel error intended to be read like not.Found.
var Found = errors.New("not found")
// Available is an error that indicates that a value is not available.
//
//lint:ignore ST1012 This is a sentinel error intended to be read like not.Available.
var Available = errors.New("not available")

55
app/types/not/valids.go Normal file
View File

@@ -0,0 +1,55 @@
//go:build windows || darwin
package not
import (
"fmt"
)
type ValidError struct {
name string
msg string
args []any
}
// Valid returns a new validation error with the given name and message.
func Valid(name, message string, args ...any) error {
return ValidError{name, message, args}
}
// Message returns the formatted message for the validation error.
func (e *ValidError) Message() string {
return fmt.Sprintf(e.msg, e.args...)
}
// Error implements the error interface.
func (e ValidError) Error() string {
return fmt.Sprintf("invalid %s: %s", e.name, e.Message())
}
func (e ValidError) Field() string {
return e.name
}
// Valids is for building a list of validation errors.
type Valids []ValidError
// Addf adds a validation error to the list with a formatted message using fmt.Sprintf.
func (b *Valids) Add(name, message string, args ...any) {
*b = append(*b, ValidError{name, message, args})
}
func (b Valids) Error() string {
if len(b) == 0 {
return ""
}
var result string
for i, err := range b {
if i > 0 {
result += "; "
}
result += err.Error()
}
return result
}

View File

@@ -0,0 +1,43 @@
//go:build windows || darwin
package not_test
import (
"errors"
"fmt"
"github.com/ollama/ollama/app/types/not"
)
func ExampleValids() {
// This example demonstrates how to use the Valids type to create
// a list of validation errors.
//
// The Valids type is a slice of ValidError values. Each ValidError
// value represents a validation error.
//
// The Valids type has an Error method that returns a single error
// value that represents all of the validation errors in the list.
//
// The Valids type is useful for collecting multiple validation errors
// and returning them as a single error value.
validate := func() error {
var b not.Valids
b.Add("name", "must be a valid name")
b.Add("email", "%q: must be a valid email address", "invalid.email")
return b
}
err := validate()
var nv not.Valids
if errors.As(err, &nv) {
for _, v := range nv {
fmt.Println(v)
}
}
// Output:
// invalid name: must be a valid name
// invalid email: "invalid.email": must be a valid email address
}