Documentation
¶
Index ¶
- Variables
- func Check(ctx context.Context, cfg *model.Cfg, s any, log *logger.Log) error
- func CheckSimple(s any) error
- func HostFromURL(rawURL string) (string, error)
- func NewValidator() (*validator.Validate, error)
- func Problem404() *problems.Problem
- func ValidateDocumentData(ctx context.Context, completeDocument *model.CompleteDocument, log *logger.Log) error
- type Error
- type ErrorResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDocumentIsRevoked is returned when a document is revoked ErrDocumentIsRevoked = NewError("DOCUMENT_IS_REVOKED") // ErrNoTransactionID is returned when transactionID is not present ErrNoTransactionID = NewError("NO_TRANSACTION_ID") // ErrNoDocumentFound is returned when no document is found ErrNoDocumentFound = NewError("NO_DOCUMENT_FOUND") // ErrDocumentAlreadyExists is returned when a document already exists ErrDocumentAlreadyExists = NewError("DOCUMENT_ALREADY_EXISTS") // ErrNoDocumentData is returned when no document_data is found ErrNoDocumentData = NewError("NO_DOCUMENT_DATA") // ErrNoIdentityFound is returned when no identity is found ErrNoIdentityFound = NewError("NO_IDENTITY_FOUND") // ErrDuplicateKey is returned when a duplicate key is found ErrDuplicateKey = NewError("DUPLICATE_KEY") // ErrNoRevocationID is returned when no revocation_id is found ErrNoRevocationID = NewError("NO_REVOCATION_ID") // ErrPrivateKeyMissing error for empty private key ErrPrivateKeyMissing = NewError("ERR_PRIVATE_KEY_MISSING") // ErrNoKnownVCT error for no known vct ErrNoKnownVCT = NewError("ERR_NO_KNOWN_VCT") // ErrInternalServerError error for internal server error ErrInternalServerError = NewError("INTERNAL_SERVER_ERROR") // ErrDocumentValidationFailed error for document validation failed ErrDocumentValidationFailed = NewError("DOCUMENT_VALIDATION_FAILED") )
Functions ¶
func CheckSimple ¶
CheckSimple checks for validation error with a simpler signature
func HostFromURL ¶
HostFromURL extracts the host (including any port) from a URL string. Unlike strings.TrimLeft, this correctly handles all URL schemes and paths.
Example ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
host, err := helpers.HostFromURL("https://example.com:8080/path")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(host)
}
Output: example.com:8080
Example (NoHost) ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
_, err := helpers.HostFromURL("not-a-url")
fmt.Println("error:", err)
}
Output: error: URL "not-a-url" has no host
Example (WithoutPort) ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
host, err := helpers.HostFromURL("https://example.com/path/to/resource")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(host)
}
Output: example.com
func NewValidator ¶
NewValidator creates a new validator
func Problem404 ¶
func ValidateDocumentData ¶
func ValidateDocumentData(ctx context.Context, completeDocument *model.CompleteDocument, log *logger.Log) error
ValidateDocumentData validates DocumentData against the schemaRef in MetaData.DocumentDataValidationRef
Types ¶
type Error ¶
type Error struct {
Title string `json:"title"`
Err any `json:"details"`
HTTPStatus int `json:"-"` // HTTP status code to return, 0 means auto-detect
}
Error is a struct that represents an error
func NewError ¶
Example ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
err := helpers.NewError("NOT_FOUND")
fmt.Println(err)
}
Output: Error: [NOT_FOUND]
func NewErrorDetails ¶
Example ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
err := helpers.NewErrorDetails("VALIDATION_FAILED", "field 'name' is required")
fmt.Println(err)
}
Output: Error: [VALIDATION_FAILED] field 'name' is required
func NewErrorDetailsWithStatus ¶
NewErrorDetailsWithStatus creates a new Error with details and an explicit HTTP status code
func NewErrorFromError ¶
NewErrorFromError creates a new Error from an error
func NewErrorWithStatus ¶
NewErrorWithStatus creates a new Error with an explicit HTTP status code
Example ¶
package main
import (
"fmt"
"github.com/SUNET/vc/pkg/helpers"
)
func main() {
err := helpers.NewErrorWithStatus("UNAUTHORIZED", 401)
fmt.Println(err)
fmt.Println("status:", err.HTTPStatus)
}
Output: Error: [UNAUTHORIZED] status: 401
type ErrorResponse ¶
type ErrorResponse struct {
Error *Error `json:"error"`
}
ErrorResponse is a struct that represents an error response in JSON from REST API