// -- Main function -- // Sets up server and Tasks struct, starts listening on 8080 func main() { //set flags configFile := flag.String("config", "", "An optional filepath for a config file.") flag.Parse() if *configFile != "" { log.Printf("configFile: " + *configFile) } //setup tasks tasks := new(Tasks) tasks.ConfigFile = *configFile //load config tasks.SetupAmqpConnection() //setup resource handler and routes handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } err := handler.SetRoutes( rest.RouteObjectMethod("POST", "/tasks", tasks, "PostTask"), ) if err != nil { log.Fatal(err) } log.Fatal(http.ListenAndServe(":8080", &handler)) }
func main() { api := Api{} api.initDB() handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } handler.SetRoutes( rest.RouteObjectMethod("GET", "/api/users", &api, "GetAllUsers"), rest.RouteObjectMethod("POST", "/api/users", &api, "PostUser"), rest.RouteObjectMethod("GET", "/api/users/:id", &api, "GetUser"), /*&rest.RouteObjectMethod("PUT", "/api/users/:id", &api, "PutUser"),*/ rest.RouteObjectMethod("DELETE", "/api/users/:id", &api, "DeleteUser"), ) http.ListenAndServe(":"+HTTPREST_SERVERPORT, &handler) }
func main() { api := Api{} api.initDB() handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } handler.SetRoutes( rest.RouteObjectMethod("GET", "/api/entries", &api, "GetAllEntries"), rest.RouteObjectMethod("POST", "/api/entries", &api, "PostEntry"), rest.RouteObjectMethod("GET", "/api/entries/:id", &api, "GetEntry"), //rest.RouteObjectMethod("PUT", "/api/entriess/:id", &api, "PutEntry"), rest.RouteObjectMethod("DELETE", "/api/entries/:id", &api, "DeleteEntry"), ) http.ListenAndServe(":8082", &handler) }
func main() { ports := ports{ Store: map[string]*Port{}, } handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } handler.SetRoutes( rest.RouteObjectMethod("GET", "/ports", &ports, "GetAllPorts"), rest.RouteObjectMethod("POST", "/ports", &ports, "PostPort"), rest.RouteObjectMethod("GET", "/ports/:id/:name", &ports, "GetPort"), rest.RouteObjectMethod("PUT", "/ports/:id", &ports, "PutPort"), rest.RouteObjectMethod("DELETE", "/ports/:id", &ports, "DeletePort"), ) http.ListenAndServe(":8080", &handler) }
func main() { users := Users{ Store: map[string]*User{}, } handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } handler.SetRoutes( rest.RouteObjectMethod("GET", "/users", &users, "GetAllUsers"), rest.RouteObjectMethod("POST", "/users", &users, "PostUser"), rest.RouteObjectMethod("GET", "/users/:id", &users, "GetUser"), rest.RouteObjectMethod("PUT", "/users/:id", &users, "PutUser"), rest.RouteObjectMethod("DELETE", "/users/:id", &users, "DeleteUser"), ) http.ListenAndServe(":8080", &handler) }
func main() { api := Api{} api.InitDB() api.InitSchema() handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } handler.SetRoutes( &rest.RouteObjectMethod("GET", "/reminders", &api, "GetAllReminders"), &rest.RouteObjectMethod("POST", "/reminders", &api, "PostReminder"), &rest.RouteObjectMethod("GET", "/reminders/:id", &api, "GetReminder"), &rest.RouteObjectMethod("PUT", "/reminders/:id", &api, "PutReminder"), &rest.RouteObjectMethod("DELETE", "/reminders/:id", &api, "DeleteReminder"), ) http.ListenAndServe(":8080", &handler) }
func main() { api := Api{} api.LoadConfig() api.InitDB() api.InitSchema() handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } err := handler.SetRoutes( rest.RouteObjectMethod("GET", "/users/:name", &api, "GetUser"), rest.RouteObjectMethod("POST", "/users", &api, "CreateUser"), rest.RouteObjectMethod("DELETE", "/users/:name", &api, "DeleteUser"), rest.RouteObjectMethod("POST", "/login", &api, "LoginUser"), rest.RouteObjectMethod("POST", "/logout", &api, "LogoutUser"), ) if err != nil { log.Fatal(err) } log.Fatal(http.ListenAndServe(":8080", &handler)) }
func StartClientApi() { handler := rest.ResourceHandler{ EnableRelaxedContentType: true, } //api := clientApi{} err := handler.SetRoutes( rest.RouteObjectMethod("POST", "/jobs", api, "CreateJob"), ) if err != nil { log.Fatal(err) } api.server = manners.NewServer() glog.Info("client api starting") api.server.ListenAndServe(":8080", &handler) }
func main() { api := tagging.Api{} api.Init() handler := rest.ResourceHandler{EnableRelaxedContentType: true} handler.SetRoutes( rest.RouteObjectMethod("GET", "/api/resumes/p/:start", &api, "ListResumes"), rest.RouteObjectMethod("GET", "/api/resumes/:id", &api, "GetResumeById"), rest.RouteObjectMethod("POST", "/api/tags", &api, "SaveTag"), rest.RouteObjectMethod("DELETE", "/api/tags/:id", &api, "DeleteTagById"), rest.RouteObjectMethod("GET", "/api/tagformats", &api, "ListTagFormats"), rest.RouteObjectMethod("POST", "/api/tagformats", &api, "SaveTagFormat"), rest.RouteObjectMethod("DELETE", "/api/tagformats/:tag", &api, "DeleteTagFormatByTag"), ) http.ListenAndServe(":8080", &handler) }
func main() { api := uictrl.Api{} api.InitDB() logger.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr) handler := rest.ResourceHandler{ EnableRelaxedContentType: true, DisableXPoweredBy: true, } handler.SetRoutes( //Contacts rest.RouteObjectMethod("GET", "/contacts", &api, "GetAllContacts"), rest.RouteObjectMethod("GET", "/contacts/:id", &api, "GetContact"), rest.RouteObjectMethod("PUT", "/contacts/:id", &api, "PutContact"), rest.RouteObjectMethod("POST", "/contacts", &api, "CreateContact"), rest.RouteObjectMethod("DELETE", "/contacts/:id", &api, "DeleteContact"), //Circles rest.RouteObjectMethod("GET", "/circles", &api, "GetAllCircles"), rest.RouteObjectMethod("GET", "/circles/:id", &api, "GetCircle"), rest.RouteObjectMethod("POST", "/circles", &api, "CreateCircle"), rest.RouteObjectMethod("DELETE", "/circles/:id", &api, "DeleteCircle"), //Posts rest.RouteObjectMethod("GET", "/posts", &api, "GetAllPosts"), rest.RouteObjectMethod("GET", "/posts/:id", &api, "GetPost"), rest.RouteObjectMethod("POST", "/posts", &api, "CreatePost"), rest.RouteObjectMethod("DELETE", "/posts/:id", &api, "DeletePost"), //Comments rest.RouteObjectMethod("GET", "/comments", &api, "GetAllComments"), rest.RouteObjectMethod("GET", "/comments/:id", &api, "GetComment"), rest.RouteObjectMethod("POST", "/comments", &api, "CreateComment"), rest.RouteObjectMethod("DELETE", "/comments/:id", &api, "DeleteComment"), //Profiles rest.RouteObjectMethod("GET", "/profiles", &api, "GetProfiles"), rest.RouteObjectMethod("GET", "/profiles/:id", &api, "GetProfile"), rest.RouteObjectMethod("DELETE", "/profiles/:id", &api, "DeleteProfile"), rest.RouteObjectMethod("POST", "/profiles", &api, "CreateProfile"), rest.RouteObjectMethod("PUT", "/profiles/:id", &api, "PutProfile"), rest.RouteObjectMethod("DELETE", "/profile_picture", &api, "DeleteProfilePicture"), //Onion rest.RouteObjectMethod("GET", "/onions", &api, "GetAllOnions"), rest.RouteObjectMethod("POST", "/onions", &api, "CreateOnion"), rest.RouteObjectMethod("GET", "/authors", &api, "GetAllAuthors"), rest.RouteObjectMethod("GET", "/originators", &api, "GetAllOriginators"), rest.RouteObjectMethod("GET", "/authors/:id", &api, "GetAuthor"), rest.RouteObjectMethod("GET", "/originators/:id", &api, "GetOriginator"), rest.RouteObjectMethod("GET", "/onions/:id", &api, "GetOnion"), //rest.RouteObjectMethod("POST", "/authors", &api, "CreateOnion"), //rest.RouteObjectMethod("POST", "/originator", &api, "CreateOnion"), //rest.RouteObjectMethod("DELETE", "/author/:id", &api, "DeleteOnion"), //rest.RouteObjectMethod("DELETE", "/author/:id", &api, "DeleteOnion"), ////Users rest.RouteObjectMethod("POST", "/users", &api, "CreateUser"), rest.RouteObjectMethod("POST", "/authorize", &api, "Authorize"), ) http.HandleFunc("/profile_picture", func(w http.ResponseWriter, r *http.Request) { log.Printf("Receiving profile picture ...\n") api.ProfilePictureHandler(w, r) }) http.HandleFunc("/sync", func(w http.ResponseWriter, r *http.Request) { api.SyncHandler(w, r) }) http.HandleFunc("/trigger", func(w http.ResponseWriter, r *http.Request) { api.TriggerHandler(w, r) }) http.HandleFunc("/pending_posts", func(w http.ResponseWriter, r *http.Request) { api.PendingPostsHandler(w, r) }) http.HandleFunc("/pending_contacts", func(w http.ResponseWriter, r *http.Request) { api.PendingContactsHandler(w, r) }) http.Handle("/api/", http.StripPrefix("/api", &handler)) http.Handle("/", http.FileServer(http.Dir("."))) log.Fatal(http.ListenAndServe(":8080", nil)) }