db

package
v0.0.0-...-c7bd76e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LatLongMultiplier = 1000000
)

Variables

This section is empty.

Functions

func SanitizeString

func SanitizeString(s string) string

SanitizeString removes all non-alphanumeric characters from a string, except for commas, dots, minus signs, and underscores.

func WithinCircumference

func WithinCircumference(point1, point2 Location, distance int) bool

WithinCircumference calculates if two Location points are within the same geographic circumference of diameter equal to the specified distance. The function takes in three arguments: - location1: a Location struct with latitude and longitude in microdegrees (1e-6 degrees) - location2: a Location struct with latitude and longitude in microdegrees (1e-6 degrees) - distance: an integer representing the diameter of the circumference in meters The function returns a boolean value indicating whether the two Location points are within the same circumference of diameter equal to the distance.

Types

type Database

type Database struct {
	*genji.DB
}

func New

func New(path string) (*Database, error)

func (*Database) Close

func (db *Database) Close() error

func (*Database) CreateTables

func (db *Database) CreateTables() error

type DateRange

type DateRange struct {
	From uint32 `json:"from"`
	To   uint32 `json:"to"`
}

DateRange is a type that represents a date range in UNIX format time.

type HexBytes

type HexBytes []byte

HexBytes is a []byte which encodes as hexadecimal in json, as opposed to the base64 default.

func (HexBytes) MarshalJSON

func (b HexBytes) MarshalJSON() ([]byte, error)

func (*HexBytes) String

func (b *HexBytes) String() string

func (*HexBytes) UnmarshalJSON

func (b *HexBytes) UnmarshalJSON(data []byte) error

type Image

type Image struct {
	Hash    []byte `json:"hash"`
	Name    string `json:"name"`
	Content []byte `json:"content"`
	Link    string `json:"link"`
}

Image is a type that represents an image.

type Location

type Location struct {
	Latitude  int64 `json:"latitude"`
	Longitude int64 `json:"longitude"`
}

Location is a type that represents a location, with latitude and longitude in microdegrees.

func NewLocation

func NewLocation(start Location, distanceNorthKm, distanceEastKm float64) Location

NewLocation creates a new location that is a certain distance (in kilometers) north and east from a starting location. The distance is approximated using a simple flat Earth model, which is reasonably accurate for small distances (up to a few hundred kilometers).

type Tool

type Tool struct {
	ID               int64       `json:"id"`
	Title            string      `json:"title"`
	Description      string      `json:"description"`
	IsAvailable      bool        `json:"isAvailable" genji:"isAvailable"`
	MayBeFree        bool        `json:"mayBeFree" genji:"mayBeFree"`
	AskWithFee       bool        `json:"askWithFee" genji:"askWithFee"`
	Cost             uint64      `json:"cost"`
	UserID           string      `json:"userId" genji:"userId"`
	Images           []Image     `json:"images"`
	TransportOptions []Transport `json:"transportOptions" genji:"transportOptions"`
	ToolCategory     int         `json:"toolCategory" genji:"toolCategory"`
	Location         Location    `json:"location"`
	Rating           int32       `json:"rating"`
	EstimatedValue   uint64      `json:"estimatedValue" genji:"estimatedValue"`
	Height           uint32      `json:"height"`
	Weight           uint32      `json:"weight"`
	ReservedDates    []DateRange `json:"reservedDates" genji:"reservedDates"`
}

Tool is a tool that can be borrowed by a user.

func (Tool) String

func (t Tool) String() string

type ToolCategory

type ToolCategory struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

ToolCategory contains the categories for the tools. The ID zero is reserved for non existing category.

type Transport

type Transport struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

Transport is a type that represents a transport.

type User

type User struct {
	Email      string   `json:"email"`
	Name       string   `json:"name"`
	Community  string   `json:"community"`
	Password   []byte   `json:"-"`
	Tokens     uint64   `json:"tokens"`
	Active     bool     `json:"active"`
	Rating     int32    `json:"rating"`
	AvatarHash HexBytes `json:"avatarHash" genji:"avatarHash"` // hash of the image
	Location   Location `json:"location"`
	Verified   bool     `json:"-"`
}

User is a type that represents a user of the app.

Jump to

Keyboard shortcuts

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