vali

package module
v0.0.0-...-095f466 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 7 Imported by: 0

README

go-vali

This package has moved to github.com/twpayne/go-igc/civlovs. This repo is archived.

PkgGoDev

Package vali provides a client interface to CIVL's Open Validation Server.

Example

func ExampleClient_ValidateIGC() {
    filename := "testdata/2006-06-10-XXX-3XI-01.IGC"
    igcFile, err := os.Open(filename)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer igcFile.Close()
    ctx := context.Background()
    if status, _, err := vali.NewClient().ValidateIGC(ctx, filename, igcFile); status == vali.Valid {
        fmt.Println("OK")
    } else {
        fmt.Println(err)
    }
    // Output: OK
}

A simple command line client is included. Install and run it with:

$ go install github.com/twpayne/go-vali/cmd/vali@latest
$ vali filename.igc
filename.igc: Valid
$ echo $?
0

The exit code is 0 if the IGC file is valid, 1 if it is invalid, or 2 if it could not be validated.

License

MIT

Documentation

Overview

Package vali provides a client interface to CIVL's Open Validation Server. See http://vali.fai-civl.org/webservice.html.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a validator service client.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient returns a new Client.

func (*Client) ValidateIGC

func (s *Client) ValidateIGC(ctx context.Context, filename string, igcFile io.Reader) (Status, *Response, error)

ValidateIGC validates igcFile.

Example
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/twpayne/go-vali"
)

func main() {
	filename := "testdata/2006-06-10-XXX-3XI-01.IGC"
	igcFile, err := os.Open(filename)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer igcFile.Close()
	ctx := context.Background()
	if status, _, err := vali.NewClient().ValidateIGC(ctx, filename, igcFile); status == vali.StatusValid {
		fmt.Println("OK")
	} else {
		fmt.Println(err)
	}
}
Output:
OK

type ClientOption

type ClientOption func(*Client)

An ClientOption is an option for configuring a Client.

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

WithEndpoint sets the HTTP endpoint.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets the http.WithHTTPClient.

type Response

type Response struct {
	Result string `json:"result"`
	Status string `json:"status"`
	Msg    string `json:"msg"`
	IGC    string `json:"igc"`
	Ref    string `json:"ref"`
	Server string `json:"server"`
}

A Response represents a response from the server.

func (Response) Passed

func (r Response) Passed() bool

type ServerError

type ServerError struct {
	HTTPStatusCode int
	HTTPStatus     string
}

A ServerError represents a server error.

func (*ServerError) Error

func (se *ServerError) Error() string

type Status

type Status int

A Status indicates the validity of an IGC file.

const (
	StatusUnknown Status = iota // Unknown indicates that the validity of the IGC file is unknown.
	StatusValid                 // Valid indicates that the IGC file is valid.
	StatusInvalid               // Invalid indicates that the IGC file is invalid.
)

func (Status) String

func (s Status) String() string

Directories

Path Synopsis
cmd
vali command

Jump to

Keyboard shortcuts

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