goan

package
v0.0.0-...-6d6f3f6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package goan contains the actual API; the main.go file simply shells out the execution to LoadAPI()

Index

Constants

This section is empty.

Variables

View Source
var (
	//LogInfo logs at the Info level (default Stdout)
	LogInfo *log.Logger
	//LogWarning logs at the Warning level (default Stdout)
	LogWarning *log.Logger
	//LogError logs at the Error level (default Stderr)
	LogError *log.Logger
)

Functions

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

func CheckAuthentication

func CheckAuthentication(config *Config) gin.HandlerFunc

CheckAuthentication will check the user's authentication token in either the post body or the query string (in that priority order)

func DeleteAllTestingEntriesMongo

func DeleteAllTestingEntriesMongo(entryType string, config *Config) error

DeleteAllTestingEntriesMongo removes all entries of a specific type. While it can be used for all removals, including non-testing, you probably don't really want to delete all of your entries

func GetDistinctEntries

func GetDistinctEntries(config *Config, authenticated bool) (int, gin.H)

GetDistinctEntries gets the distinct entries

func GetDistinctEntriesMongo

func GetDistinctEntriesMongo(config *Config) ([]string, error)

GetDistinctEntriesMongo gets the distinct entry types that have been input

func GetEntriesByType

func GetEntriesByType(entryType string, from time.Time, to time.Time, sort Sort, config *Config, authenticated bool) (int, gin.H)

GetEntriesByType gets a list of all entries filtered by a specific type

func SaveEntry

func SaveEntry(entryType string, reference string, notes string, config *Config, authenticated bool) (int, gin.H)

SaveEntry saves a new event entry to the database

func SaveEntryMongo

func SaveEntryMongo(data *DataEntry, config *Config) error

SaveEntryMongo saves a DataEntry struct to Mongo

func SetupLogger

func SetupLogger()

SetupLogger sets up logging for the application

Types

type Config

type Config struct {
	AuthenticationToken string
	Port                string
	DatabaseType        string // currently only Mongo, with MySQL and others coming soon*
	DatabaseName        string
	DatabaseHost        string
	DatabaseUser        string
	DatabasePassword    string
	DatabasePort        string
	DatabaseURL         string //overrides other entries
	DatabaseMongo       mgo.Session
}

Config holds basic configuration options for the application, including database settings and authentication

func LoadAPI

func LoadAPI() (*gin.Engine, *Config)

LoadAPI is the entry point for the application. It will start the GIN server

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig will load up a new configuration struct with sane defaults if none provided

type DataEntry

type DataEntry struct {
	MongoID      bson.ObjectId `bson:"_id"`
	SQLID        int           `bson:"_sqlid"`
	EntryType    string        `bson:"entryType" json:"entryType"`
	Reference    string        `bson:"reference" json:"reference"`
	EntryCreated time.Time     `bson:"entryCreated" json:"entryCreated"`
	Notes        string        `bson:"notes" json:"notes"`
}

DataEntry is the primary data structure for the events that are logged

The primary fields are: - EntryType: The type of event, such as "login" or "userSubscribed" - Reference: An optional field for referencing another record. For example, if the "entryType" is "user", this could hold a reference to the user Id - EntryCreated: The time the event occurred - Notes: Any optional notes to go along with the event

func GetEntriesByTypeMongo

func GetEntriesByTypeMongo(entryType string, from time.Time, to time.Time, sort Sort, config *Config) ([]DataEntry, error)

GetEntriesByTypeMongo returns a slice of DataEntry objects by the specified filters

func (DataEntry) EntryReturnHelper

func (dataEntry DataEntry) EntryReturnHelper() gin.H

EntryReturnHelper formats the return of a DataEntry object back to the client

type Sort

type Sort struct {
	Start     int
	Count     int
	Field     string
	Direction string
}

Sort holds a structure of sort options

func ParseSort

func ParseSort(c *gin.Context, field string) Sort

ParseSort parses the Gin context and takes in a default field to sort on. All other fields are set with sane defaults.

func (*Sort) ModifySortForMongo

func (sort *Sort) ModifySortForMongo()

ModifySortForMongo takes a sort object and modifes it for use in the Mongo API

Jump to

Keyboard shortcuts

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