Skip to content

Commit

Permalink
Merge pull request #2 from oers/master
Browse files Browse the repository at this point in the history
Provide a webpath to serve content under
  • Loading branch information
ian-kent committed Mar 13, 2016
2 parents 1a4b117 + cf83ed4 commit 5b86b47
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
30 changes: 15 additions & 15 deletions api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ var stream *goose.EventStream
type ReleaseConfig config.OutgoingSMTP

func CreateAPIv1(conf *config.Config, r *pat.Router) *APIv1 {
log.Println("Creating API v1")
log.Println("Creating API v1 with WebPath: " + conf.WebPath)
apiv1 := &APIv1{
config: conf,
}

stream = goose.NewEventStream()

r.Path("/api/v1/messages").Methods("GET").HandlerFunc(apiv1.messages)
r.Path("/api/v1/messages").Methods("DELETE").HandlerFunc(apiv1.delete_all)
r.Path("/api/v1/messages").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/messages").Methods("GET").HandlerFunc(apiv1.messages)
r.Path(conf.WebPath + "/api/v1/messages").Methods("DELETE").HandlerFunc(apiv1.delete_all)
r.Path(conf.WebPath + "/api/v1/messages").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

r.Path("/api/v1/messages/{id}").Methods("GET").HandlerFunc(apiv1.message)
r.Path("/api/v1/messages/{id}").Methods("DELETE").HandlerFunc(apiv1.delete_one)
r.Path("/api/v1/messages/{id}").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("GET").HandlerFunc(apiv1.message)
r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("DELETE").HandlerFunc(apiv1.delete_one)
r.Path(conf.WebPath + "/api/v1/messages/{id}").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

r.Path("/api/v1/messages/{id}/download").Methods("GET").HandlerFunc(apiv1.download)
r.Path("/api/v1/messages/{id}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/messages/{id}/download").Methods("GET").HandlerFunc(apiv1.download)
r.Path(conf.WebPath + "/api/v1/messages/{id}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("GET").HandlerFunc(apiv1.download_part)
r.Path("/api/v1/messages/{id}/mime/part/{part}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/messages/{id}/mime/part/{part}/download").Methods("GET").HandlerFunc(apiv1.download_part)
r.Path(conf.WebPath + "/api/v1/messages/{id}/mime/part/{part}/download").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

r.Path("/api/v1/messages/{id}/release").Methods("POST").HandlerFunc(apiv1.release_one)
r.Path("/api/v1/messages/{id}/release").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/messages/{id}/release").Methods("POST").HandlerFunc(apiv1.release_one)
r.Path(conf.WebPath + "/api/v1/messages/{id}/release").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

r.Path("/api/v1/events").Methods("GET").HandlerFunc(apiv1.eventstream)
r.Path("/api/v1/events").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)
r.Path(conf.WebPath + "/api/v1/events").Methods("GET").HandlerFunc(apiv1.eventstream)
r.Path(conf.WebPath + "/api/v1/events").Methods("OPTIONS").HandlerFunc(apiv1.defaultOptions)

go func() {
for {
Expand Down
24 changes: 12 additions & 12 deletions api/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ type APIv2 struct {
}

func CreateAPIv2(conf *config.Config, r *pat.Router) *APIv2 {
log.Println("Creating API v2")
log.Println("Creating API v2 with WebPath: " + conf.WebPath)
apiv2 := &APIv2{
config: conf,
}

r.Path("/api/v2/messages").Methods("GET").HandlerFunc(apiv2.messages)
r.Path("/api/v2/messages").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path(conf.WebPath + "/api/v2/messages").Methods("GET").HandlerFunc(apiv2.messages)
r.Path(conf.WebPath + "/api/v2/messages").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)

r.Path("/api/v2/search").Methods("GET").HandlerFunc(apiv2.search)
r.Path("/api/v2/search").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path(conf.WebPath + "/api/v2/search").Methods("GET").HandlerFunc(apiv2.search)
r.Path(conf.WebPath + "/api/v2/search").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)

r.Path("/api/v2/jim").Methods("GET").HandlerFunc(apiv2.jim)
r.Path("/api/v2/jim").Methods("POST").HandlerFunc(apiv2.createJim)
r.Path("/api/v2/jim").Methods("PUT").HandlerFunc(apiv2.updateJim)
r.Path("/api/v2/jim").Methods("DELETE").HandlerFunc(apiv2.deleteJim)
r.Path("/api/v2/jim").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path(conf.WebPath + "/api/v2/jim").Methods("GET").HandlerFunc(apiv2.jim)
r.Path(conf.WebPath + "/api/v2/jim").Methods("POST").HandlerFunc(apiv2.createJim)
r.Path(conf.WebPath + "/api/v2/jim").Methods("PUT").HandlerFunc(apiv2.updateJim)
r.Path(conf.WebPath + "/api/v2/jim").Methods("DELETE").HandlerFunc(apiv2.deleteJim)
r.Path(conf.WebPath + "/api/v2/jim").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)

r.Path("/api/v2/outgoing-smtp").Methods("GET").HandlerFunc(apiv2.listOutgoingSMTP)
r.Path("/api/v2/outgoing-smtp").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)
r.Path(conf.WebPath + "/api/v2/outgoing-smtp").Methods("GET").HandlerFunc(apiv2.listOutgoingSMTP)
r.Path(conf.WebPath + "/api/v2/outgoing-smtp").Methods("OPTIONS").HandlerFunc(apiv2.defaultOptions)

return apiv2
}
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func DefaultConfig() *Config {
MongoColl: "messages",
StorageType: "memory",
CORSOrigin: "",
WebPath: "",
MessageChan: make(chan *data.Message),
OutgoingSMTP: make(map[string]*OutgoingSMTP),
}
Expand All @@ -43,6 +44,7 @@ type Config struct {
Monkey monkey.ChaosMonkey
OutgoingSMTPFile string
OutgoingSMTP map[string]*OutgoingSMTP
WebPath string
}

type OutgoingSMTP struct {
Expand Down

0 comments on commit 5b86b47

Please sign in to comment.