server

package
v0.0.0-...-1de5769 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const MaxHeight = 256
View Source
const MaxWidth = 256
View Source
const (
	PageSize = 20
)
View Source
const ProcessingTimeout = 5

Variables

View Source
var (
	TagExists   = errors.New("tag already exists")
	TagNotExist = errors.New("tag does not exist")
)

Functions

func CanAccessDirectory

func CanAccessDirectory(serv *Server) bool

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem)

FileServer conveniently sets up a http.FileServer handler to serve static files from a http.FileSystem.

func GenPhotoID

func GenPhotoID(f io.ReadSeeker) (string, error)

func GetDeleted

func GetDeleted(r *http.Request) (bool, error)

func GetExif

func GetExif(out chan *exif.Exif, data io.Reader, wg ProcessorWaitGroup, errs chan error)

func GetPaginateValues

func GetPaginateValues(r *http.Request) (int, int, error)

func GetTag

func GetTag(r *http.Request) string

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request)

func ProcessPhoto

func ProcessPhoto(input io.Reader, id string, photoPath string, thumbPath string, timeout time.Duration) (*exif.Exif, *image.Rectangle, error)

func SaveImage

func SaveImage(data io.Reader, path string, wg ProcessorWaitGroup, errs chan error)

func SaveThumb

func SaveThumb(r chan *image.Rectangle, data io.Reader, path string, wg ProcessorWaitGroup, errs chan error)

func WriteError

func WriteError(s string, status int, w http.ResponseWriter)

func WriteJsonResponse

func WriteJsonResponse(v interface{}, status int, w http.ResponseWriter)

Types

type DeletePhotoResponse

type DeletePhotoResponse struct {
	Success bool   `json:"success"`
	ID      string `json:"id"`
}

type DeleteTagResponse

type DeleteTagResponse struct {
	Success bool     `json:"success"`
	ID      string   `json:"id"`
	Tags    []string `json:"tags"`
}

type ErrorResponse

type ErrorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

type ExifData

type ExifData interface {
	DateTime() (time.Time, error)
	LatLong() (float64, float64, error)
	Get(name exif.FieldName) (*tiff.Tag, error)
}

type GetPagesResponse

type GetPagesResponse struct {
	Success bool `json:"success"`
	MaxPage int  `json:"max_page"`
	Photos  int  `json:"photos"`
}

type GetPhotoIDsResponse

type GetPhotoIDsResponse struct {
	Success bool     `json:"success"`
	IDs     []string `json:"ids"`
}

type GetPhotoMetadataResponse

type GetPhotoMetadataResponse struct {
	Success bool  `json:"success"`
	Photo   Photo `json:"photo"`
}

type GetPhotosResponse

type GetPhotosResponse struct {
	Success bool    `json:"success"`
	Photos  []Photo `json:"photos"`
}

type GetTagsResponse

type GetTagsResponse struct {
	Success bool     `json:"success"`
	ID      string   `json:"id"`
	Tags    []string `json:"tags"`
}

type NotFoundResponse

type NotFoundResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
	URI     string `json:"uri"`
}

type Photo

type Photo struct {
	ID              string     `storm:"id" json:"id"`
	Deleted         bool       `storm:"index" json:"deleted"` // CANNOT BE OMITTED IN JSON BECAUSE STORM
	UploadedAt      *time.Time `storm:"index" json:"uploaded_at"`
	TakenAt         *time.Time `storm:"index" json:"taken_at"`
	Width           int        `storm:"index" json:"width"`
	Height          int        `storm:"index" json:"height"`
	Megapixels      float64    `storm:"index" json:"megapixels"`
	Lat             float64    `json:"lat"`
	Long            float64    `json:"long"`
	CamSerial       string     `storm:"index" json:"cam_serial"`
	CamMake         string     `storm:"index" json:"cam_make"`
	CamModel        string     `storm:"index" json:"cam_model"`
	Status          Status     `storm:"index" json:"status"`
	StatusUpdatedAt *time.Time `storm:"index" json:"status_updated_at"`
	Tags            []string   `storm:"index" json:"tags"` // not performant, but I don't care
}

func NewPhoto

func NewPhoto(id string) Photo

func (*Photo) AddMetadata

func (p *Photo) AddMetadata(r *image.Rectangle, x ExifData)

func (*Photo) AddTag

func (p *Photo) AddTag(tag string) error

func (*Photo) DeleteTag

func (p *Photo) DeleteTag(tag string) error

func (*Photo) UpdateStatus

func (p *Photo) UpdateStatus(status Status)

type PhotoDB

type PhotoDB interface {
	All(to interface{}, options ...func(*index.Options)) error
	Count(data interface{}) (int, error)
	DeleteStruct(data interface{}) error
	Find(fieldName string, value interface{}, to interface{}, options ...func(q *index.Options)) error
	Init(data interface{}) error
	One(fieldName string, value interface{}, to interface{}) error
	Save(data interface{}) error
	Select(matchers ...q.Matcher) storm.Query
	UpdateField(data interface{}, fieldName string, value interface{}) error
	Update(data interface{}) error
}

type PhotoQuery

type PhotoQuery interface {
	Skip(int) PhotoQuery
	Limit(int) PhotoQuery
	OrderBy(...string) PhotoQuery
}

type PostPhotoResponse

type PostPhotoResponse struct {
	Success bool   `json:"success"`
	Status  Status `json:"status"`
	NewID   string `json:"new_id"`
}

type PostTagResponse

type PostTagResponse struct {
	Success bool     `json:"success"`
	ID      string   `json:"id"`
	Tags    []string `json:"tags"`
}

type ProcessorWaitGroup

type ProcessorWaitGroup interface {
	Add(delta int)
	Done()
	Wait()
}

type Server

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

* Server struct

func New

func New(cfg *config.Config) (*Server, error)

func (*Server) DeletePhoto

func (s *Server) DeletePhoto(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteTag

func (s *Server) DeleteTag(w http.ResponseWriter, r *http.Request)

func (*Server) GetImage

func (s *Server) GetImage(imageFormat string, w http.ResponseWriter, r *http.Request)

func (*Server) GetPages

func (s *Server) GetPages(w http.ResponseWriter, r *http.Request)

func (*Server) GetPhoto

func (s *Server) GetPhoto(w http.ResponseWriter, r *http.Request)

func (*Server) GetPhotoFromDatabase

func (s *Server) GetPhotoFromDatabase(photoID string) (Photo, error)

func (*Server) GetPhotoIDs

func (s *Server) GetPhotoIDs(w http.ResponseWriter, r *http.Request)

func (*Server) GetPhotoMetadata

func (s *Server) GetPhotoMetadata(w http.ResponseWriter, r *http.Request)

func (*Server) GetPhotos

func (s *Server) GetPhotos(w http.ResponseWriter, r *http.Request)

func (*Server) GetTags

func (s *Server) GetTags(w http.ResponseWriter, r *http.Request)

func (*Server) GetThumbnail

func (s *Server) GetThumbnail(w http.ResponseWriter, r *http.Request)

func (*Server) PhotoCtx

func (s *Server) PhotoCtx(next http.Handler) http.Handler

func (*Server) PostPhoto

func (s *Server) PostPhoto(w http.ResponseWriter, r *http.Request)

func (*Server) PostTag

func (s *Server) PostTag(w http.ResponseWriter, r *http.Request)

func (*Server) Run

func (s *Server) Run()

func (*Server) Setup

func (s *Server) Setup() error

func (*Server) TagCtx

func (s *Server) TagCtx(next http.Handler) http.Handler

type Status

type Status uint8
const (
	Processing          Status = iota
	ProcessingSucceeded Status = iota
	ProcessingFailed    Status = iota
)

func ToStatus

func ToStatus(s string) Status

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

func (*Status) String

func (s *Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

type TagMatcher

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

func (*TagMatcher) MatchField

func (m *TagMatcher) MatchField(v interface{}) (bool, error)

Jump to

Keyboard shortcuts

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