This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hostname, _ := os.Hostname() | |
| value := someWork() | |
| fmt.Printf("PUTVAL %s/my-plugin/gauge-my_metric interval=%d N:%s\n", hostname, interval, value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "flag" | |
| "time" | |
| ) | |
| func main() { | |
| var ( | |
| interval = flag.Int("interval", 5, "time in seconds between collection") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bufio" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net" | |
| "os" | |
| "strings" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn get-all-todo | |
| [] | |
| (let [result (jdbc/with-db-connection | |
| [conn (db-connection)] | |
| (jdbc/query conn | |
| ["select * from todo_list"]))] | |
| {:status 200 | |
| :body {:result result}})) | |
| (defn create-todo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn create-table | |
| [] | |
| (jdbc/db-do-commands | |
| (db-connection) | |
| (jdbc/create-table-ddl :todo_list | |
| [[:id :int "PRIMARY KEY AUTO_INCREMENT"] | |
| [:title "varchar(30)"] | |
| [:text "varchar(1024)"]]))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def db-config | |
| {:classname "org.h2.Driver" | |
| :subprotocol "h2" | |
| :subname "mem:todo" | |
| :user "" | |
| :password ""}) | |
| (defn pool | |
| [config] | |
| (let [cpds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defroutes app-routes | |
| (GET "/" [] (get-all-todo)) | |
| (POST "/" {params :params} (create-todo params)) | |
| (context "/:id" [id] | |
| (GET "/" [] (get-todo id)) | |
| (PUT "/" {params :params} (update-todo id params)) | |
| (DELETE "/" [] (delete-todo id))) | |
| (not-found "sorry")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def app | |
| (-> app-routes | |
| wrap-json-params | |
| wrap-json-response)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns todo-rest.core | |
| (:require [ring.adapter.jetty :as jetty] | |
| [ring.middleware.reload :refer [wrap-reload]] | |
| [compojure.core :refer [defroutes context GET POST PUT DELETE]] | |
| [compojure.route :refer [not-found]]) | |
| (:gen-class)) | |
| (defroutes app-routes | |
| (GET "/" [] {:status 200 :body "hello world" :headers {}}) | |
| (not-found "sorry")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defproject todo-rest "0.1.0-SNAPSHOT" | |
| :description "FIXME: write description" | |
| :url "http://example.com/FIXME" | |
| :license {:name "Eclipse Public License" | |
| :url "http://www.eclipse.org/legal/epl-v10.html"} | |
| :dependencies [[org.clojure/clojure "1.8.0"] | |
| [ring "1.5.0"] | |
| [compojure "1.5.1"]] | |
| :min-lein-version "2.0.0" | |
| :main todo-rest.core |