├── images ├── api.png ├── group.png └── home.png ├── Dockerfile ├── src ├── main │ ├── resources │ │ ├── banner.txt │ │ ├── text.properties │ │ └── html │ │ │ ├── index.html │ │ │ ├── group.html │ │ │ ├── style.css │ │ │ └── about.html │ └── nim │ │ ├── main.nim │ │ ├── server │ │ ├── handlers │ │ │ ├── post.nim │ │ │ ├── delete.nim │ │ │ ├── put.nim │ │ │ └── get.nim │ │ ├── instance.nim │ │ ├── context.nim │ │ └── server.nim │ │ ├── settings.nim │ │ └── properties.nim └── test │ └── nim │ └── server │ └── context_test.nim ├── CHANGELOG.md ├── .gitignore ├── CONTRIBUTING.md ├── config.nims ├── LICENSE └── README.md /images/api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxlabaza/luntic/HEAD/images/api.png -------------------------------------------------------------------------------- /images/group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxlabaza/luntic/HEAD/images/group.png -------------------------------------------------------------------------------- /images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxlabaza/luntic/HEAD/images/home.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM alpine:3.6 3 | MAINTAINER Artem Labazin 4 | 5 | COPY build/docker/luntic /luntic 6 | 7 | ENTRYPOINT ["/luntic"] 8 | CMD ["--debug", "0.0.0.0"] 9 | -------------------------------------------------------------------------------- /src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 2 | __ __ _ 3 | / / __ __ ____ / /_ (_)_____ 4 | / / / / / // __ \ / __// // ___/ 5 | / /___/ /_/ // / / // /_ / // /__ 6 | /_____/\__,_//_/ /_/ \__//_/ \___/ 7 | 8 | I was born! 9 | -------------------------------------------------------------------------------- /src/main/nim/main.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import properties, 18 | settings, 19 | strutils, 20 | server/server 21 | 22 | 23 | const 24 | BANNER = "banner.txt".staticRead 25 | WELCOME_REST = prop"welcome.rest" 26 | WELCOME_DASHBOARD = prop"welcome.dashboard" 27 | 28 | 29 | when isMainModule: 30 | 31 | let options = settings.parseArguments() 32 | 33 | echo BANNER 34 | if options.dashboard > 0: 35 | echo WELCOME_DASHBOARD.format(options.address, options.port, options.pathPrefix, options.dashboard) 36 | else: 37 | echo WELCOME_REST.format(options.address, options.port, options.pathPrefix) 38 | 39 | server.start(options) 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Changelog 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 7 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 8 | 9 | [Tags on this repository](https://github.com/xxlabaza/luntic/tags) 10 | 11 | ## [Unreleased] 12 | 13 | - Restric access via `Basic Authorization`. 14 | 15 | ## [1.1.0](https://github.com/xxlabaza/luntic/releases/tag/1.1.0) - 2017-07-29 16 | 17 | ### Added 18 | - `Docker` build task, `Dockerfile` and possibility to create Docker images. 19 | - Headers print in `debug` mode. 20 | 21 | ### Changed 22 | - Default listening address from `localhost` to `0.0.0.0`. 23 | 24 | ## [1.0.1](https://github.com/xxlabaza/luntic/releases/tag/1.0.1) - 2017-07-24 25 | 26 | ### Added 27 | - `X-Expired-Time` header in creation response, for telling in which time client should make `PUT` request again. If `--heartbeat` option is not set - this header will have `0` value. 28 | 29 | ### Changed 30 | - Corrected README.md file 31 | 32 | ## [1.0.0](https://github.com/xxlabaza/luntic/releases/tag/1.0.0) - 2017-07-22 33 | 34 | Initial release. 35 | 36 | ### Added 37 | - CRUD endpoints for service registration and management. 38 | - Scheduled periodical task for removing expired records. 39 | - Dashborad, which you could launch on separate port and open in your web browser. 40 | -------------------------------------------------------------------------------- /src/main/resources/text.properties: -------------------------------------------------------------------------------- 1 | 2 | name=luntic 3 | version=v1.1.0 4 | 5 | default.port=8080 6 | default.pathPrefix=/ 7 | default.address=0.0.0.0 8 | default.heartbeat=0 9 | 10 | usage=\ 11 | Usage: ${name} [OPTIONS] [LISTENING_ADDRESS] \ 12 | \ 13 | A lightweight REST in-memory discovery service \ 14 | \ 15 | Options: \ 16 | -p:PORT --port=PORT sets listening port \ 17 | default: ${default.port} \ 18 | --path-prefix=PATH sets server's endpoints path prefix \ 19 | default: '${default.pathPrefix}' \ 20 | --heartbeat=SECONDS sets heartbeat service cleaner in seconds, \ 21 | if it set to 0 - turn off heartbeat scheduler \ 22 | default: ${default.heartbeat}s \ 23 | --dashboard=PORT setups a simple web browser-oriented dashboard \ 24 | for services monitoring \ 25 | default: turned off \ 26 | -d --debug turn on debug mode \ 27 | -v --version prints program's version \ 28 | -h --help prints this help menu \ 29 | 30 | welcome.rest=${version} \ 31 | Copyright (c) by Artem Labazin \ 32 | \ 33 | REST requests are serviced on: http://$1:$2$3 \ 34 | 35 | welcome.dashboard=${version} \ 36 | Copyright (c) by Artem Labazin \ 37 | \ 38 | REST requests are serviced on: http://$1:$2$3 \ 39 | Dashboard is available on: http://$1:$4/ \ 40 | -------------------------------------------------------------------------------- /src/main/nim/server/handlers/post.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asyncdispatch, 18 | ../instance, 19 | ../context, 20 | options, 21 | tables 22 | 23 | 24 | proc handle* (rc: RequestContext, groups: TableRef[string, seq[Instance]]): Future[void] = 25 | if rc.group.isNone or rc.instanceId.isSome: 26 | return rc.respond(400, "Group was not set or ID was") 27 | 28 | let 29 | group = rc.group.get() 30 | instance = newInstance(group, rc.time, rc.body.get(nil)) 31 | 32 | if not groups.hasKey(group): 33 | groups[group] = newSeq[Instance]() 34 | groups[group].add(instance) 35 | 36 | var location = rc.pathPrefix 37 | if location[location.high] != '/': 38 | location &= '/' 39 | location &= group & '/' & instance.id 40 | 41 | return rc.respond(201, instance.toJsonString(), [ 42 | ("Location", location), 43 | ("X-Expired-Time", $rc.heartbeat), 44 | ("Content-Type", "application/json") 45 | ]) 46 | -------------------------------------------------------------------------------- /src/test/nim/server/context_test.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import unittest, tables, options, uri, asynchttpserver, context 18 | 19 | proc createRequest (str: string): Request = 20 | return Request(url: Uri(path: str)) 21 | 22 | test "Parsing request parts": 23 | let toCheck = { 24 | "/api/popa": ("/api", "popa", ""), 25 | "/api/popa/": ("/api", "popa", ""), 26 | "/api/popa/123": ("/api", "popa", "123"), 27 | "/api/popa/123/": ("/api", "popa", "123"), 28 | "/api/popa/123/wow": ("/api", "", ""), 29 | "/api/": ("/api", "", ""), 30 | "/api": ("/api", "", ""), 31 | "/popa": ("/", "popa", "") 32 | }.toTable 33 | 34 | for key, value in toCheck.pairs(): 35 | let request = createRequest(key) 36 | try: 37 | let (group, id) = parsePath(value[0], request) 38 | check(value[1] == group.get()) 39 | if id.isSome: 40 | check(value[2] == id.get()) 41 | else: 42 | check(value[2] == "") 43 | except: 44 | check(("", "") == (value[1], value[2])) 45 | -------------------------------------------------------------------------------- /src/main/nim/server/handlers/delete.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asyncdispatch, 18 | ../instance, 19 | ../context, 20 | strutils, 21 | options, 22 | tables 23 | 24 | 25 | proc handle* (rc: RequestContext, groups: TableRef[string, seq[Instance]]): Future[void] = 26 | if rc.group.isNone or rc.instanceId.isNone: 27 | return rc.respond(400, "Group or ID was not set") 28 | 29 | let 30 | group = rc.group.get() 31 | instanceId = rc.instanceId.get() 32 | 33 | if not groups.hasKey(group): 34 | let msg = "There is no such group - '$1'".format(group) 35 | return rc.respond(404, msg) 36 | 37 | var 38 | instances = groups[group] 39 | index = -1 40 | 41 | for i in 0..instances.high: 42 | if instances[i].id == instanceId: 43 | index = i 44 | break 45 | 46 | if index == -1: 47 | let msg = "There is no such ID - '$1' in group '$2'".format(instanceId, group) 48 | return rc.respond(404, msg) 49 | elif instances.len == 0: 50 | groups.del(group) 51 | else: 52 | groups[group].del(index) 53 | 54 | return rc.respond(204) 55 | -------------------------------------------------------------------------------- /src/main/nim/server/handlers/put.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asyncdispatch, 18 | ../instance, 19 | ../context, 20 | strutils, 21 | options, 22 | tables 23 | 24 | 25 | proc handle* (rc: RequestContext, groups: TableRef[string, seq[Instance]]): Future[void] = 26 | if rc.group.isNone or rc.instanceId.isNone: 27 | return rc.respond(400, "Group or ID was not set") 28 | 29 | let 30 | group = rc.group.get() 31 | instanceId = rc.instanceId.get() 32 | 33 | if not groups.hasKey(group): 34 | let msg = "There is no such group - '$1'".format(group) 35 | return rc.respond(404, msg) 36 | 37 | var 38 | instances = groups[group] 39 | index = -1 40 | 41 | for i in 0..instances.high: 42 | if instances[i].id == instanceId: 43 | index = i 44 | break 45 | 46 | if index == -1: 47 | let msg = "There is no such ID - '$1' in group '$2'".format(instanceId, group) 48 | return rc.respond(404, msg) 49 | 50 | var instance = instances[index] 51 | 52 | instance.modified = rc.time 53 | if rc.body.isSome: 54 | instance.meta = rc.body.get() 55 | 56 | return rc.respond(200, instance.toJsonString(), [ 57 | ("Content-Type", "application/json") 58 | ]) 59 | -------------------------------------------------------------------------------- /src/main/nim/server/instance.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import sequtils, 18 | times, 19 | json, 20 | oids 21 | 22 | 23 | type Instance* = ref object 24 | id* : string 25 | group* : string 26 | created* : Time 27 | modified* : Time 28 | meta* : JsonNode 29 | 30 | 31 | proc newInstance* (group: string, time: Time = getTime(), meta: JsonNode = nil): Instance = 32 | result = Instance( 33 | id: $oids.genOid(), 34 | group: group, 35 | created: time, 36 | modified: time 37 | ) 38 | if not meta.isNil: 39 | result.meta = meta 40 | 41 | 42 | proc toJson* (instance: Instance): JsonNode = 43 | result = %* { 44 | "id": instance.id, 45 | "group": instance.group, 46 | "created": $instance.created, 47 | "modified": $instance.modified 48 | } 49 | 50 | if not instance.meta.isNil: 51 | result["meta"] = instance.meta 52 | 53 | 54 | proc toJson* (instances: seq[Instance]): JsonNode = 55 | let js = instances.map do (it: Instance) -> JsonNode: it.toJson() 56 | return %*js 57 | 58 | 59 | proc toJsonString* (instance: Instance): string = 60 | result = $instance.toJson() 61 | 62 | 63 | proc toJsonString* (instances: seq[Instance]): string = 64 | result = $instances.toJson() 65 | -------------------------------------------------------------------------------- /src/main/nim/server/handlers/get.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asyncdispatch, 18 | ../instance, 19 | ../context, 20 | strutils, 21 | options, 22 | tables, 23 | json 24 | 25 | 26 | proc ok (rc: RequestContext, js: JsonNode): Future[void] = 27 | return rc.respond(200, $js, [ 28 | ("Content-Type", "application/json") 29 | ]) 30 | 31 | 32 | proc handle* (rc: RequestContext, groups: TableRef[string, seq[Instance]]): Future[void] = 33 | if rc.group.isNone: 34 | var js = newJObject() 35 | for key, value in groups.pairs(): 36 | js[key] = value.toJson() 37 | return rc.ok(%*js) 38 | 39 | let group = rc.group.get() 40 | 41 | if not groups.hasKey(group): 42 | let msg = "There is no such group - '$1'".format(group) 43 | return rc.respond(404, msg) 44 | 45 | var instances = groups[group] 46 | if rc.instanceId.isNone: 47 | return rc.ok(instances.toJson()) 48 | let instanceId = rc.instanceId.get() 49 | 50 | var index = -1 51 | for i in 0..instances.high: 52 | if instances[i].id == instanceId: 53 | index = i 54 | break 55 | 56 | if index == -1: 57 | let msg = "There is no such ID - '$1' in group '$2'".format(instanceId, group) 58 | return rc.respond(404, msg) 59 | 60 | return rc.ok(instances[index].toJson()) 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | generated 2 | 3 | *.class 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # Package Files # 9 | *.jar 10 | *.war 11 | *.ear 12 | 13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 14 | hs_err_pid* 15 | 16 | *.pydevproject 17 | .metadata 18 | .gradle 19 | bin/ 20 | tmp/ 21 | *.tmp 22 | *.bak 23 | *.swp 24 | *~.nib 25 | local.properties 26 | .settings/ 27 | .loadpath 28 | 29 | # Eclipse Core 30 | .project 31 | 32 | # External tool builders 33 | .externalToolBuilders/ 34 | 35 | # Locally stored "Eclipse launch configurations" 36 | *.launch 37 | 38 | # CDT-specific 39 | .cproject 40 | 41 | # JDT-specific (Eclipse Java Development Tools) 42 | .classpath 43 | 44 | # Java annotation processor (APT) 45 | .factorypath 46 | 47 | # PDT-specific 48 | .buildpath 49 | 50 | # sbteclipse plugin 51 | .target 52 | 53 | # TeXlipse plugin 54 | .texlipse 55 | 56 | # STS (Spring Tool Suite) 57 | .springBeans 58 | 59 | # Windows image file caches 60 | Thumbs.db 61 | ehthumbs.db 62 | 63 | # Folder config file 64 | Desktop.ini 65 | 66 | # Recycle Bin used on file shares 67 | $RECYCLE.BIN/ 68 | 69 | # Windows Installer files 70 | *.cab 71 | *.msi 72 | *.msm 73 | *.msp 74 | # Windows shortcuts 75 | *.lnk 76 | target/ 77 | pom.xml.tag 78 | pom.xml.releaseBackup 79 | pom.xml.versionsBackup 80 | pom.xml.next 81 | release.properties 82 | dependency-reduced-pom.xml 83 | buildNumber.properties 84 | .mvn/timing.properties 85 | /.project 86 | /.settings/ 87 | /.classpath 88 | *.classpath 89 | *.project 90 | *.classpath 91 | *.project 92 | /.apt_generated/ 93 | 94 | # IntelliJ Idea 95 | .idea/ 96 | *.iml 97 | *.ipr 98 | *.iws 99 | out/ 100 | 101 | # Netbeans 102 | nbproject/private/ 103 | build/ 104 | nbbuild/ 105 | dist/ 106 | nbdist/ 107 | nbactions.xml 108 | nb-configuration.xml 109 | .nb-gradle/ 110 | 111 | # Test output log file 112 | .DS_Store 113 | .vscode/ 114 | -------------------------------------------------------------------------------- /src/main/nim/settings.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import properties, 18 | parseopt2, 19 | strutils 20 | 21 | 22 | type Settings* = object of RootObj 23 | port* : int 24 | pathPrefix* : string 25 | address* : string 26 | heartbeat* : int 27 | debug*: bool 28 | dashboard*: int 29 | 30 | 31 | const 32 | VERSION = prop"version" 33 | USAGE = prop"usage" 34 | DEFAUL_PORT = prop"default.port" 35 | DEFAUL_PATH_PREFIX = prop"default.pathPrefix" 36 | DEFAUL_ADDRESS = prop"default.address" 37 | DEFAUL_HEARTBEAT = prop"default.heartbeat" 38 | 39 | 40 | proc parseArguments* (): Settings = 41 | result = Settings( 42 | port: parseInt(DEFAUL_PORT), 43 | pathPrefix: DEFAUL_PATH_PREFIX, 44 | address: DEFAUL_ADDRESS, 45 | heartbeat: parseInt(DEFAUL_HEARTBEAT), 46 | debug: false, 47 | dashboard: -1 48 | ) 49 | 50 | for kind, key, value in getopt(): 51 | case kind: 52 | of cmdArgument: 53 | result.address = key 54 | of cmdLongOption, cmdShortOption: 55 | case key: 56 | of "p", "port": 57 | result.port = parseInt(value) 58 | of "path-prefix": 59 | result.pathPrefix = value 60 | of "heartbeat": 61 | result.heartbeat = parseInt(value) 62 | of "dashboard": 63 | result.dashboard = parseInt(value) 64 | of "d", "debug": 65 | result.debug = true 66 | of "h", "help": 67 | echo USAGE 68 | quit QuitSuccess 69 | of "v", "version": 70 | echo VERSION 71 | quit QuitSuccess 72 | else: 73 | echo "Nope" 74 | quit QuitFailure 75 | of cmdEnd: 76 | assert(false) # cannot happen 77 | -------------------------------------------------------------------------------- /src/main/nim/properties.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import tables, 18 | strutils, 19 | parseutils 20 | 21 | 22 | type IllegalPropertyException = object of Exception 23 | 24 | let content {.compileTime.} = "text.properties".staticRead 25 | 26 | 27 | proc parseValue (map: Table[string, string], str: string): string = 28 | result = "" 29 | 30 | var index = 0 31 | while index < str.len: 32 | var before = "" 33 | index += str.parseUntil(before, "${", index) 34 | result &= before 35 | 36 | if index >= str.len: 37 | break 38 | index += 2 39 | 40 | var key = "" 41 | index += str.parseUntil(key, {'}', '\0'}, index) 42 | if not map.hasKey(key): 43 | let message = "Illegal property '$1' in string '$2'".format(key, str) 44 | raise newException(IllegalPropertyException, message) 45 | result &= map[key] 46 | 47 | index += 1 48 | 49 | 50 | proc parseSingleLine (line: string): (string, string) = 51 | let tokens = line.split({ ':', '=' }, 1) 52 | if tokens.len != 2: 53 | let message = "Property '$1' is invalid".format(line) 54 | raise newException(IllegalPropertyException, message) 55 | 56 | let key = tokens[0].strip() 57 | 58 | var value = tokens[1].strip() 59 | if value.startsWith("'") and value.endsWith("'"): 60 | value = value[1..(value.high - 1)] 61 | elif value.startsWith("\"") and value.endsWith("\""): 62 | value = value[1..(value.high - 1)] 63 | 64 | return (key, value) 65 | 66 | 67 | proc parseProperties (): Table[string, string] {.compileTime.} = 68 | result = initTable[string, string]() 69 | 70 | var multiLineKey:string = nil 71 | for line in content.splitLines: 72 | let trimmedLine = line.strip(false) 73 | if trimmedLine.len == 0 or trimmedLine.startsWith("#"): 74 | if not multiLineKey.isNilOrEmpty: 75 | multiLineKey = nil 76 | continue 77 | 78 | if multiLineKey.isNilOrEmpty: 79 | let parsedLine = parseSingleLine(trimmedLine) 80 | var value = parsedLine[1] 81 | if trimmedLine.endsWith('\\'): 82 | value = value.replace("\\", "\n") 83 | multiLineKey = parsedLine[0] 84 | result[parsedLine[0]] = result.parseValue(value) 85 | else: 86 | let value = trimmedLine.replace("\\", "\n") 87 | result[multiLineKey] &= result.parseValue(value) 88 | if not trimmedLine.endsWith('\\'): 89 | multiLineKey = nil 90 | 91 | 92 | let properties {.compileTime.} = parseProperties() 93 | 94 | 95 | proc prop* (path: string): string {.compileTime.} = 96 | return properties[path] 97 | -------------------------------------------------------------------------------- /src/main/resources/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Luntic 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | Luntic 18 | 19 | 20 | 24 |
25 | 26 |
27 |

Groups

28 |

29 | List of registered application groups: 30 |

31 |
32 |
33 |
34 |
35 | 36 |
37 | Copyright 2017 Artem Labazin / 38 | GitHub 39 |
40 | 41 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /src/main/nim/server/context.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asynchttpserver, 18 | asyncdispatch, 19 | sequtils, 20 | strutils, 21 | options, 22 | tables, 23 | times, 24 | json 25 | 26 | 27 | type RequestContext* = object 28 | pathPrefix* : string 29 | group* : Option[string] 30 | instanceId* : Option[string] 31 | body* : Option[JsonNode] 32 | request* : Request 33 | heartbeat* : int 34 | time* : Time 35 | 36 | 37 | proc parsePath* (pathPrefix: string, request: Request): (Option[string], Option[string]) = 38 | let emptyTuple = (none(string), none(string)) 39 | 40 | let path = request.url.path 41 | if path.isNilOrEmpty: 42 | return emptyTuple 43 | 44 | let contextPath = path.substr(pathPrefix.len) 45 | if contextPath.isNilOrEmpty: 46 | return emptyTuple 47 | 48 | let tokens = contextPath.split('/') 49 | .filter do (it: string) -> bool : not it.isNilOrEmpty 50 | 51 | if tokens.len == 1: 52 | return (some(tokens[0]), none(string)) 53 | elif tokens.len > 2: 54 | let msg = "the request '$1' contains incorrect path parts: $2".format(contextPath, tokens) 55 | raise newException(Exception, msg) 56 | else: 57 | return (some(tokens[0]), some(tokens[1])) 58 | 59 | 60 | proc parseBody* (request: Request): Option[JsonNode] = 61 | let jsonText = request.body 62 | if jsonText.isNilOrEmpty: 63 | return none(JsonNode) 64 | 65 | var json:JsonNode = nil 66 | try: 67 | json = parseJson(jsonText) 68 | except: 69 | return none(JsonNode) 70 | return some(json) 71 | 72 | 73 | proc initRequestContext* (pathPrefix: string, heartbeat: int, request: Request): RequestContext = 74 | let (group, instanceId) = parsePath(pathPrefix, request) 75 | result = RequestContext( 76 | pathPrefix: pathPrefix, 77 | group: group, 78 | instanceId: instanceId, 79 | body: parseBody(request), 80 | request: request, 81 | heartbeat: heartbeat, 82 | time: getTime() 83 | ) 84 | 85 | 86 | proc respond* (rc: RequestContext; status: int; content: string = ""; headers: openarray[tuple[key: string, val: string]] = []): Future[void] = 87 | let code = HttpCode(status) 88 | let httpHeaders = newHttpHeaders(headers) 89 | return respond(rc.request, code, content, httpHeaders) 90 | 91 | 92 | 93 | when isMainModule: 94 | 95 | import uri 96 | 97 | proc createRequest (str: string): Request = 98 | let url = Uri(path: str) 99 | return Request(url: url) 100 | 101 | proc checkMe (str: string) = 102 | echo "Incoming path: $1".format(str) 103 | try: 104 | let request = createRequest(str) 105 | echo "\t" & $parsePath("/api", request) 106 | except: 107 | echo "\tError" 108 | 109 | checkMe("/api/popa/123") 110 | checkMe("/api/popa") 111 | checkMe("/api/popa/") 112 | checkMe("/api/popa/123/") 113 | checkMe("/api/popa/123/wow") 114 | checkMe("/api/") 115 | checkMe("/api") 116 | -------------------------------------------------------------------------------- /src/main/resources/html/group.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Luntic 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | Luntic 18 | 19 | 20 | 24 |
25 | 26 |
27 |

28 |

29 | List of registered instances in group: 30 |

31 | 32 |
33 |
34 | 35 |
36 |
37 | 38 |
39 | Copyright 2017 Artem Labazin / 40 | GitHub 41 |
42 | 43 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /src/main/nim/server/server.nim: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Artem Labazin . 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import asynchttpserver, 18 | asyncdispatch, 19 | strutils, 20 | sequtils, 21 | tables, 22 | times, 23 | uri, 24 | ../settings, 25 | context, 26 | instance, 27 | handlers/post, 28 | handlers/get, 29 | handlers/put, 30 | handlers/delete 31 | 32 | 33 | const 34 | INDEX_PAGE = "html/index.html".staticRead 35 | GROUP_PAGE = "html/group.html".staticRead 36 | ABOUT_PAGE = "html/about.html".staticRead 37 | STYLE_CSS = "html/style.css".staticRead 38 | 39 | 40 | var 41 | groups {.threadvar.} : TableRef[string, seq[Instance]] 42 | pathPrefix {.threadvar.} : string 43 | debug {.threadvar.} : bool 44 | heartbeat {.threadvar.} : int 45 | 46 | 47 | proc log (request: Request) = 48 | var reqMethod = $request.reqMethod 49 | for i in reqMethod.len..<6: 50 | reqMethod &= ' ' 51 | if request.body.isNilOrEmpty: 52 | echo "$1 -- $2 $3".format(getTime(), reqMethod, request.url.path) 53 | else: 54 | echo "$1 -- $2 $3 $4".format(getTime(), reqMethod, request.url.path, request.body) 55 | for key, value in request.headers.table.pairs(): 56 | echo " $1: $2".format(key, $value) 57 | 58 | 59 | proc restCallback (request: Request) {.async.} = 60 | if debug: 61 | log(request) 62 | 63 | if not request.url.path.startsWith(pathPrefix): 64 | await request.respond(Http400, "Only root path ($1) request allowed".format(pathPrefix)) 65 | else: 66 | let rc = initRequestContext(pathPrefix, heartbeat, request) 67 | case request.reqMethod: 68 | of HttpPost: 69 | await post.handle(rc, groups) 70 | of HttpGet: 71 | await get.handle(rc, groups) 72 | of HttpPut: 73 | await put.handle(rc, groups) 74 | of HttpDelete: 75 | await delete.handle(rc, groups) 76 | else: 77 | await request.respond(Http405, "Awailable methods: GET, POST, PUT, DELETE") 78 | 79 | 80 | proc staticCallback (request: Request) {.async.} = 81 | let path = request.url.path 82 | 83 | if path.startsWith("/api"): 84 | var apiRequest = request 85 | if path != "/api": 86 | apiRequest.url.path = path["/api".len..path.high] 87 | else: 88 | apiRequest.url.path = pathPrefix 89 | await restCallback(apiRequest) 90 | return 91 | 92 | if request.reqMethod != HttpGet: 93 | await request.respond(Http405, "Awailable methods: GET") 94 | return 95 | 96 | var content:string 97 | case path: 98 | of "/": 99 | content = INDEX_PAGE 100 | of "/group": 101 | content = GROUP_PAGE 102 | of "/about": 103 | content = ABOUT_PAGE 104 | of "/style.css": 105 | let headers = newHttpHeaders([("Content-Type", "text/css")]) 106 | await request.respond(Http200, STYLE_CSS, headers) 107 | return 108 | else: 109 | await request.respond(Http404, "") 110 | return 111 | 112 | let headers = newHttpHeaders([ 113 | ("Content-Type", "text/html"), 114 | ("Set-Cookie", "pathPrefix=" & pathPrefix) 115 | ]) 116 | await request.respond(Http200, content, headers) 117 | 118 | 119 | proc scheduler (timeout: int) {.async.} = 120 | let interval = seconds(timeout) 121 | while true: 122 | await sleepAsync(timeout * 1_000) 123 | let time = getTime() 124 | if debug: 125 | echo "$1 -- REMOVER STARTED".format(time) 126 | for key in groups.keys(): 127 | groups[key].keepItIf(it.modified > (time - interval)) 128 | if groups[key].len == 0: 129 | groups.del(key) 130 | 131 | 132 | proc start* (settings: Settings) = 133 | groups = newTable[string, seq[Instance]]() 134 | pathPrefix = settings.pathPrefix 135 | debug = settings.debug 136 | heartbeat = settings.heartbeat 137 | 138 | let heartbeat = settings.heartbeat 139 | if heartbeat > 0: 140 | asyncCheck scheduler(heartbeat) 141 | 142 | if settings.dashboard > 0: 143 | asyncCheck newAsyncHttpServer().serve(Port(settings.dashboard), staticCallback, settings.address) 144 | 145 | waitFor newAsyncHttpServer().serve(Port(settings.port), restCallback, settings.address) 146 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributing 3 | 4 | When contributing to this repository, please first discuss the change you wish to make via issue, 5 | email, or any other method with the owners of this repository before making a change. 6 | 7 | Please note we have a code of conduct, please follow it in all your interactions with the project. 8 | 9 | ## Pull Request Process 10 | 11 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 13 | 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 14 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 15 | 16 | ## Code of Conduct 17 | 18 | ### Our Pledge 19 | 20 | In the interest of fostering an open and welcoming environment, we as 21 | contributors and maintainers pledge to making participation in our project and 22 | our community a harassment-free experience for everyone, regardless of age, body 23 | size, disability, ethnicity, gender identity and expression, level of experience, 24 | nationality, personal appearance, race, religion, or sexual identity and 25 | orientation. 26 | 27 | ### Our Standards 28 | 29 | Examples of behavior that contributes to creating a positive environment 30 | include: 31 | 32 | * Using welcoming and inclusive language 33 | * Being respectful of differing viewpoints and experiences 34 | * Gracefully accepting constructive criticism 35 | * Focusing on what is best for the community 36 | * Showing empathy towards other community members 37 | 38 | Examples of unacceptable behavior by participants include: 39 | 40 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 41 | * Trolling, insulting/derogatory comments, and personal or political attacks 42 | * Public or private harassment 43 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 44 | * Other conduct which could reasonably be considered inappropriate in a professional setting 45 | 46 | ### Our Responsibilities 47 | 48 | Project maintainers are responsible for clarifying the standards of acceptable 49 | behavior and are expected to take appropriate and fair corrective action in 50 | response to any instances of unacceptable behavior. 51 | 52 | Project maintainers have the right and responsibility to remove, edit, or 53 | reject comments, commits, code, wiki edits, issues, and other contributions 54 | that are not aligned to this Code of Conduct, or to ban temporarily or 55 | permanently any contributor for other behaviors that they deem inappropriate, 56 | threatening, offensive, or harmful. 57 | 58 | ### Scope 59 | 60 | This Code of Conduct applies both within project spaces and in public spaces 61 | when an individual is representing the project or its community. Examples of 62 | representing a project or community include using an official project e-mail 63 | address, posting via an official social media account, or acting as an appointed 64 | representative at an online or offline event. Representation of a project may be 65 | further defined and clarified by project maintainers. 66 | 67 | ### Enforcement 68 | 69 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 70 | reported by contacting the project team at xxlabaza@gmail.com. All 71 | complaints will be reviewed and investigated and will result in a response that 72 | is deemed necessary and appropriate to the circumstances. The project team is 73 | obligated to maintain confidentiality with regard to the reporter of an incident. 74 | Further details of specific enforcement policies may be posted separately. 75 | 76 | Project maintainers who do not follow or enforce the Code of Conduct in good 77 | faith may face temporary or permanent repercussions as determined by other 78 | members of the project's leadership. 79 | 80 | ## License 81 | 82 | By contributing your code, you agree to license your contribution under the terms of the [APLv2](./LICENSE) 83 | 84 | All files are released with the Apache 2.0 license. 85 | 86 | If you are adding a new file it should have a header like this: 87 | 88 | ``` 89 | # 90 | # Copyright 2017 Artem Labazin . 91 | # 92 | # Licensed under the Apache License, Version 2.0 (the "License"); 93 | # you may not use this file except in compliance with the License. 94 | # You may obtain a copy of the License at 95 | # 96 | # http://www.apache.org/licenses/LICENSE-2.0 97 | # 98 | # Unless required by applicable law or agreed to in writing, software 99 | # distributed under the License is distributed on an "AS IS" BASIS, 100 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 101 | # See the License for the specific language governing permissions and 102 | # limitations under the License. 103 | # 104 | ``` 105 | -------------------------------------------------------------------------------- /config.nims: -------------------------------------------------------------------------------- 1 | 2 | import strutils 3 | 4 | mode = ScriptMode.Verbose 5 | 6 | let 7 | binaryName = "luntic" 8 | mainFileName = "main" 9 | version = "1.1.0" 10 | buildFolder = thisDir() & '/' & "build" 11 | buildSourcesMainFolder = buildFolder & "/sources/main" 12 | buildSourcesTestFolder = buildFolder & "/sources/test" 13 | buildCacheFolder = buildFolder & "/cache" 14 | buildTargetFolder = buildFolder & "/target" 15 | buildDockerFolder = buildFolder & "/docker" 16 | buildResourcesMainFolder = buildFolder & "/resources/main" 17 | buildResourcesTestFolder = buildFolder & "/resources/test" 18 | buildBinaryFile = buildTargetFolder & "/" & binaryName 19 | sourcesFolder = thisDir() & '/' & "src" 20 | sourcesMainFolder = sourcesFolder & "/main" 21 | sourcesMainNimFolder = sourcesMainFolder & "/nim" 22 | sourcesMainResourcesFolder = sourcesMainFolder & "/resources" 23 | sourcesTestFolder = sourcesFolder & "/test" 24 | sourcesTestNimFolder = sourcesTestFolder & "/nim" 25 | sourcesTestResourcesFolder = sourcesTestFolder & "/resources" 26 | sourcesMainFile = buildSourcesMainFolder & "/" & mainFileName 27 | 28 | 29 | 30 | template dependsOn (tasks: untyped) = 31 | for taskName in astToStr(tasks).split({',', ' '}): 32 | exec "nim " & taskName 33 | 34 | 35 | proc build_create () = 36 | for folder in @[buildSourcesMainFolder, buildCacheFolder, buildTargetFolder]: 37 | if not dirExists folder: 38 | mkdir folder 39 | if dirExists sourcesMainResourcesFolder: 40 | mkdir buildResourcesMainFolder 41 | 42 | 43 | proc build_copy () = 44 | build_create() 45 | if dirExists sourcesMainNimFolder: 46 | exec "cp -r $1/* $2".format(sourcesMainNimFolder, buildSourcesMainFolder) 47 | if dirExists(sourcesMainResourcesFolder) and listFiles(sourcesMainResourcesFolder).len > 0: 48 | exec "cp -r $1/* $2".format(sourcesMainResourcesFolder, buildResourcesMainFolder) 49 | 50 | 51 | proc test_copy () = 52 | build_copy() 53 | if dirExists(sourcesTestNimFolder) and listFiles(sourcesTestNimFolder).len > 0: 54 | if not dirExists buildSourcesTestFolder: 55 | mkdir buildSourcesTestFolder 56 | exec "cp -r $1/* $2".format(sourcesTestNimFolder, buildSourcesTestFolder) 57 | if dirExists(sourcesTestResourcesFolder) and listFiles(sourcesTestResourcesFolder).len > 0: 58 | if not dirExists buildResourcesTestFolder: 59 | mkdir buildResourcesTestFolder 60 | exec "cp -r $1/* $2".format(sourcesTestResourcesFolder, buildResourcesTestFolder) 61 | 62 | 63 | proc folders (dir: string): seq[string] = 64 | result = newSeq[string]() 65 | result.add(dir) 66 | for child in listDirs(dir): 67 | result.add(folders(child)) 68 | 69 | 70 | proc findTestFiles (): seq[string] = 71 | result = newSeq[string]() 72 | for folder in folders(buildSourcesTestFolder): 73 | for file in listFiles(folder): 74 | if file.endsWith("_test.nim"): 75 | result.add(file) 76 | 77 | 78 | proc addAllBuildPaths () = 79 | switch "path", buildSourcesMainFolder 80 | if existsDir buildResourcesMainFolder: 81 | switch "path", buildResourcesMainFolder 82 | 83 | for folder in folders(buildSourcesMainFolder): 84 | switch "path", folder 85 | 86 | 87 | proc collectPaths (folder: string): string = 88 | result = "" 89 | for child in folders(folder): 90 | result &= " --path:" & child 91 | 92 | 93 | task clean, "cleans the project": 94 | if dirExists buildFolder: 95 | rmdir buildFolder 96 | else: 97 | echo "Nothing to clean" 98 | 99 | 100 | task test, "tests the project": 101 | dependsOn clean 102 | test_copy() 103 | 104 | var command = "nim compile" 105 | command &= collectPaths(buildSourcesMainFolder) 106 | command &= collectPaths(buildResourcesMainFolder) 107 | command &= collectPaths(buildSourcesTestFolder) 108 | command &= collectPaths(buildResourcesTestFolder) 109 | 110 | command &= " --nimcache:" & buildCacheFolder 111 | command &= " --out:" & buildTargetFolder & "/test" 112 | command &= " --verbosity:0" 113 | command &= " --run " 114 | 115 | for file in findTestFiles(): 116 | exec command & file 117 | rmFile buildTargetFolder & "/test" 118 | 119 | 120 | task build, "builds the project": 121 | if paramCount() == 2 and paramStr(2) == "release": 122 | dependsOn test 123 | switch "define", "release" 124 | else: 125 | dependsOn clean 126 | build_copy() 127 | 128 | --verbosity:1 129 | switch "out", buildBinaryFile 130 | switch "nimcache", buildCacheFolder 131 | 132 | addAllBuildPaths() 133 | setCommand "compile", sourcesMainFile 134 | 135 | 136 | task init, "initialize a project": 137 | for folder in @[sourcesMainNimFolder, sourcesMainResourcesFolder, sourcesTestNimFolder, sourcesTestResourcesFolder]: 138 | mkdir folder 139 | exec "echo 'echo \"Hello world\"' > $1/$2.nim".format(sourcesMainNimFolder, mainFileName) 140 | 141 | 142 | task docker, "builds the project within specific docker container": 143 | dependsOn clean 144 | build_copy() 145 | 146 | exec "mkdir -p $1".format(buildDockerFolder) 147 | 148 | exec """docker run \ 149 | --rm \ 150 | -v '$1:/tmp/src' \ 151 | -v '$2:/tmp/target' \ 152 | xxlabaza/nim:0.17.0 \ 153 | compile --define:release \ 154 | --symbolFiles:off \ 155 | --nimcache:/tmp/src/cache \ 156 | --path:/tmp/src/sources/main \ 157 | --path:/tmp/src/resources/main \ 158 | --out:/tmp/target/$3 \ 159 | /tmp/src/sources/main/$4""".format(buildFolder, buildDockerFolder, binaryName, mainFileName) 160 | 161 | exec "docker build --force-rm=true --tag xxlabaza/luntic:$1 .".format(version) 162 | 163 | 164 | task run, "runs the project": 165 | dependsOn build 166 | 167 | var command = buildBinaryFile 168 | for parameterIndex in 2..paramCount(): 169 | command &= ' ' & paramStr(parameterIndex) 170 | 171 | exec command 172 | setCommand "nop" 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2017 Artem Labazin. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /src/main/resources/html/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | font-family: Menlo, Monaco, "DejaVu Sans Mono", Consolas, monospace; 4 | font-size: 14px; 5 | background: #eee; 6 | } 7 | 8 | 9 | 10 | .container { 11 | max-width: 700px; 12 | padding: 10px; 13 | margin: auto; 14 | background: #fff; 15 | border: 1px solid #ddd; 16 | } 17 | 18 | @media(min-width: 300px){ 19 | .container { 20 | padding: 20px 20px; 21 | } 22 | } 23 | 24 | @media(min-width: 700px){ 25 | .container { 26 | padding: 40px 80px; 27 | } 28 | } 29 | 30 | header { 31 | overflow: hidden; 32 | padding-bottom: 21px; 33 | } 34 | header nav { 35 | float: right 36 | } 37 | header span { 38 | float: left; 39 | } 40 | 41 | a { 42 | color: #a0f; 43 | text-decoration: none; 44 | } 45 | 46 | a:hover { 47 | border-bottom: 1px solid; 48 | } 49 | time { color: #aaa;} 50 | article time { 51 | display: block; 52 | text-align: right; 53 | } 54 | 55 | [data-rmd] h1 { 56 | font-weight: bold; 57 | text-align: center; 58 | text-transform: uppercase; 59 | } 60 | [data-rmd] h1::before { 61 | content: "" 62 | } 63 | [data-rmd] h2 { 64 | font-weight: bold; 65 | } 66 | [data-rmd] h2::before { 67 | color: #aaa; 68 | } 69 | [data-rmd] h3 { 70 | font-weight: bold; 71 | } 72 | [data-rmd] h3::before { 73 | color: #aaa; 74 | } 75 | [data-rmd] code { 76 | color: #999; 77 | } 78 | [data-rmd] em { 79 | font-style: italic; 80 | } 81 | [data-rmd] strong { 82 | font-weight: bold; 83 | } 84 | 85 | [data-rmd] a.img::before { content: "" } 86 | [data-rmd] a.img::after { content: "" } 87 | [data-rmd] a.img span { 88 | display: block; text-align: center; 89 | } 90 | [data-rmd] a.img:hover span { 91 | text-decoration: underline; 92 | } 93 | 94 | 95 | pre { overflow: auto; } 96 | 97 | p.source { text-align: center; color: #aaa; } 98 | p.share { text-align: center; } 99 | p.alt { text-align: center;} 100 | footer { text-align: center; color: #aaa; font-size: 12px; padding: 10px; } 101 | p img { 102 | display: block; 103 | margin:auto; 104 | max-width: 100%; 105 | } 106 | 107 | a < img::before {content: ""} 108 | 109 | .g table {margin: auto} 110 | .g h1, .g h2 { text-align: center; } 111 | .g table img { width: 600px; } 112 | 113 | .g { 114 | max-width: 1300px; 115 | padding: 10px; 116 | margin: auto; 117 | background: #fff; 118 | border: 1px solid #ddd; 119 | } 120 | 121 | 122 | 123 | 124 | /* 125 | ReMarkdown 2.0.0 - http://fvsch.com/code/remarkdown/ 126 | [license] WTFPL - http://fvsch.com/code/remarkdown/COPYING 127 | [build info] Styles: all. Defaults: hn-hash ul-hyphen em-star strong-star a-bracket pre-indent code-tick hr-star 128 | */ 129 | [data-rmd] { line-height: 1.5; } 130 | [data-rmd] h1, [data-rmd] h2, [data-rmd] h3, [data-rmd] h4, [data-rmd] h5, [data-rmd] h6 { font-size: inherit; font-weight: inherit; } 131 | [data-rmd] h1 { margin-top: 3em; margin-bottom: 1.5em; } 132 | [data-rmd] h2 { margin-top: 3em; margin-bottom: 1.5em; } 133 | [data-rmd] h3, [data-rmd] h4, [data-rmd] h5, [data-rmd] h6 { margin-top: 1.5em; margin-bottom: 1.5em; } 134 | [data-rmd] p { margin-top: 1.5em; margin-bottom: 1.5em; } 135 | [data-rmd] figure { margin: 1.5em 0 1.5em; } 136 | [data-rmd] ul { margin-top: 1.5em; margin-bottom: 1.5em; } 137 | [data-rmd] ol { margin-top: 1.5em; margin-bottom: 1.5em; } 138 | [data-rmd] ul, [data-rmd] ol { margin-left: 3ch; padding: 0; list-style: none; } 139 | [data-rmd] ul ul, [data-rmd] ul ol, [data-rmd] ol ul, [data-rmd] ol ol { margin-top: 0; margin-bottom: 0; } 140 | [data-rmd] ul > li::before { float: left; margin-left: -3ch; width: 1ch; } 141 | [data-rmd] ol { counter-reset: item; } 142 | [data-rmd] ol > li { counter-increment: item; } 143 | [data-rmd] ol > li::before { float: left; margin-left: -4ch; width: 3ch; overflow: hidden; text-align: right; content: counter(item) "."; } 144 | [data-rmd] ol > li[value]::before { content: attr(value) "."; word-spacing: -1ch; } 145 | [data-rmd] pre { margin-top: 1.5em; margin-bottom: 1.5em; -moz-tab-size: 4; tab-size: 4; } 146 | [data-rmd] blockquote { position: relative; margin-top: 1.5em; margin-bottom: 1.5em; margin-left: 0; margin-right: 0; padding: 0; padding-left: 3ch; } 147 | [data-rmd] blockquote::before { position: absolute; top: 0; left: 0; bottom: 0; overflow: hidden; white-space: pre; content: ">\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A>\A"; cursor: default; } 148 | [data-rmd] hr { height: 1.5em; line-height: 1.5em; margin-top: 1.5em; margin-bottom: 1.5em; border: none; color: inherit; } 149 | [data-rmd] em, [data-rmd] strong { font-style: normal; font-weight: normal; } 150 | [data-rmd] pre, [data-rmd] code, [data-rmd] kbd, [data-rmd] samp, [data-rmd] tt { font-family: inherit; } 151 | 152 | [data-rmd] h1::before, [data-rmd~=hn-hash] h1::before { content: "# "; } 153 | 154 | [data-rmd~=hn-close] h1::after { content: " #"; } 155 | 156 | [data-rmd] h2::before, [data-rmd~=hn-hash] h2::before { content: "## "; } 157 | 158 | [data-rmd~=hn-close] h2::after { content: " ##"; } 159 | 160 | [data-rmd] h3::before, [data-rmd~=hn-hash] h3::before { content: "### "; } 161 | 162 | [data-rmd~=hn-close] h3::after { content: " ###"; } 163 | 164 | [data-rmd] h4::before, [data-rmd~=hn-hash] h4::before { content: "#### "; } 165 | 166 | [data-rmd~=hn-close] h4::after { content: " ####"; } 167 | 168 | [data-rmd] h5::before, [data-rmd~=hn-hash] h5::before { content: "##### "; } 169 | 170 | [data-rmd~=hn-close] h5::after { content: " #####"; } 171 | 172 | [data-rmd] h6::before, [data-rmd~=hn-hash] h6::before { content: "###### "; } 173 | 174 | [data-rmd~=hn-close] h6::after { content: " ######"; } 175 | 176 | [data-rmd~=h1-underline] h1, [data-rmd~=h2-underline] h2 { display: table; overflow: hidden; position: relative; padding-bottom: 1.5em; } 177 | [data-rmd~=h1-underline] h1::before, [data-rmd~=h2-underline] h2::before { content: none; } 178 | [data-rmd~=h1-underline] h1::after, [data-rmd~=h2-underline] h2::after { position: absolute; bottom: 0; left: 0; height: 1.5em; width: 100%; overflow: hidden; word-break: break-all; cursor: default; } 179 | 180 | [data-rmd~=h1-underline] h1::after { content: "========================================================================================================================"; } 181 | 182 | [data-rmd~=h2-underline] h2::after { content: "------------------------------------------------------------------------------------------------------------------------"; } 183 | 184 | [data-rmd] em::before, [data-rmd] em::after, [data-rmd~=em-star] em::before, [data-rmd~=em-star] em::after { content: "*"; } 185 | 186 | [data-rmd~=em-underscore] em::before, [data-rmd~=em-underscore] em::after { content: "_"; } 187 | 188 | [data-rmd] strong::before, [data-rmd] strong::after, [data-rmd~=strong-star] strong::before, [data-rmd~=strong-star] strong::after { content: "**"; } 189 | 190 | [data-rmd~=strong-underscore] strong::before, [data-rmd~=strong-underscore] strong::after { content: "__"; } 191 | 192 | [data-rmd] a::before, [data-rmd~=a-bracket] a::before { content: "["; } 193 | [data-rmd] a::after, [data-rmd~=a-bracket] a::after { content: "]"; } 194 | 195 | [data-rmd~=a-showurl] a[href]::before { content: "["; } 196 | [data-rmd~=a-showurl] a[href]::after { content: "](" attr(href) ")"; word-break: break-all; } 197 | 198 | [data-rmd~=ul-star] ul > li::before { content: "*"; } 199 | 200 | [data-rmd~=ul-plus] ul > li::before { content: "+"; } 201 | 202 | /*[data-rmd] ul > li::before, [data-rmd~=ul-hyphen] ul > li::before { content: "-"; }*/ 203 | 204 | [data-rmd] pre, [data-rmd~=pre-indent] pre { margin-left: 4ch; } 205 | 206 | [data-rmd] :not(pre) > code::before, [data-rmd] :not(pre) > code::after, [data-rmd~=code-tick] :not(pre) > code::before, [data-rmd~=code-tick] :not(pre) > code::after { content: "`"; text-shadow: 0 1px; } 207 | 208 | [data-rmd~=code-fence] pre > code { display: block; } 209 | [data-rmd~=code-fence] pre > code::before, [data-rmd~=code-fence] pre > code::after { position: relative; top: .3em; content: "```"; display: block; width: 100%; height: 1.5em; overflow: hidden; word-break: break-all; cursor: default; } 210 | 211 | [data-rmd~=code-fence-tilde] pre > code::before, [data-rmd~=code-fence-tilde] pre > code::after { top: 0; content: "~~~"; } 212 | 213 | [data-rmd~=code-fence-full] pre > code::before, [data-rmd~=code-fence-full] pre > code::after { top: 0; content: "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; } 214 | 215 | [data-rmd~=del-gfm] del { text-decoration: none; } 216 | [data-rmd~=del-gfm] del::before, [data-rmd~=del-gfm] del::after { content: "~~"; } 217 | 218 | [data-rmd~=hr-center] hr { text-align: center; } 219 | 220 | [data-rmd] hr::before, [data-rmd~=hr-star] hr::before { content: "* * * *"; } 221 | 222 | [data-rmd~=hr-hyphen] hr::before { content: "-------"; } 223 | 224 | [data-rmd~=table-marker] table { margin-top: 1.5em; margin-bottom: 1.5em; border-collapse: collapse; } 225 | [data-rmd~=table-marker] tr > * { min-width: 3ch; position: relative; padding: 0; text-align: inherit; vertical-align: top; font-weight: normal; border: none; } 226 | [data-rmd~=table-marker] tr > * + * { padding-left: 3ch; } 227 | [data-rmd~=table-marker] tr:first-child > th:not([scope="row"]) { padding-bottom: 1.5em; } 228 | [data-rmd~=table-marker] tr:first-child > th:not([scope="row"])::after { content: "--------------------------------------------------------------------------------------------------------------"; position: absolute; bottom: 0; left: 0; right: 0; overflow: hidden; word-break: break-all; height: 1.5em; } 229 | [data-rmd~=table-marker] tr:first-child > * + th:not([scope="row"])::after { left: 3ch; } 230 | [data-rmd~=table-marker] tr > * + *::before { content: "|\A|\A|\A|\A|\A|\A|\A|\A|\A|\A"; position: absolute; overflow: hidden; left: 1ch; top: 0; bottom: 0; white-space: pre; } 231 | [data-rmd~=table-marker] th[scope="row"], [data-rmd~=table-marker] tr + tr > th:first-child { padding-right: 1ch; } 232 | [data-rmd~=table-marker] th[scope="row"]::after, [data-rmd~=table-marker] tr + tr > th:first-child::after { position: absolute; right: -1ch; content: ":"; } 233 | 234 | 235 | 236 | 237 | /* highlight */ 238 | 239 | .highlight, pre.highlight { 240 | color: #5c6370 241 | } 242 | .highlight pre { 243 | background: #282c34 244 | } 245 | .highlight .hll { 246 | background: #282c34 247 | } 248 | .highlight .c { 249 | color: #5c6370; 250 | font-style: italic 251 | } 252 | .highlight .err { 253 | color: #960050; 254 | background-color: #1e0010 255 | } 256 | .highlight .k { 257 | color: #c500ff 258 | } 259 | .highlight .l { 260 | color: #48ad00 261 | } 262 | .highlight .n { 263 | color: #5c6370 264 | } 265 | .highlight .o { 266 | color: #5c6370 267 | } 268 | .highlight .p { 269 | color: #5c6370 270 | } 271 | .highlight .cm { 272 | color: #5c6370; 273 | font-style: italic 274 | } 275 | .highlight .cp { 276 | color: #5c6370; 277 | font-style: italic 278 | } 279 | .highlight .c1 { 280 | color: #929eb3; 281 | font-style: italic 282 | } 283 | .highlight .cs { 284 | color: #5c6370; 285 | font-style: italic 286 | } 287 | .highlight .ge { 288 | font-style: italic 289 | } 290 | .highlight .gs { 291 | font-weight: 700 292 | } 293 | .highlight .kc { 294 | color: #c500ff 295 | } 296 | .highlight .kd { 297 | color: #c500ff 298 | } 299 | .highlight .kn { 300 | color: #c500ff 301 | } 302 | .highlight .kp { 303 | color: #c500ff 304 | } 305 | .highlight .kr { 306 | color: #c500ff 307 | } 308 | .highlight .kt { 309 | color: #c500ff 310 | } 311 | .highlight .ld { 312 | color: #48ad00 313 | } 314 | .highlight .m { 315 | color: #d19a66 316 | } 317 | .highlight .s { 318 | color: #48ad00 319 | } 320 | .highlight .na { 321 | color: #d19a66 322 | } 323 | .highlight .nb { 324 | color: #ffa600 325 | } 326 | .highlight .nc { 327 | color: #ffa600 328 | } 329 | .highlight .no { 330 | color: #ffa600 331 | } 332 | .highlight .nd { 333 | color: #ffa600 334 | } 335 | .highlight .ni { 336 | color: #ffa600 337 | } 338 | .highlight .ne { 339 | color: #ffa600 340 | } 341 | .highlight .nf { 342 | color: #5c6370 343 | } 344 | .highlight .nl { 345 | color: #ffa600 346 | } 347 | .highlight .nn { 348 | color: #5c6370 349 | } 350 | .highlight .nx { 351 | color: #5c6370 352 | } 353 | .highlight .py { 354 | color: #ffa600 355 | } 356 | .highlight .nt { 357 | color: #e06c75 358 | } 359 | .highlight .nv { 360 | color: #ffa600 361 | } 362 | .highlight .ow { 363 | font-weight: 700 364 | } 365 | .highlight .w { 366 | color: #f8f8f2 367 | } 368 | .highlight .mf { 369 | color: #d19a66 370 | } 371 | .highlight .mh { 372 | color: #d19a66 373 | } 374 | .highlight .mi { 375 | color: #d19a66 376 | } 377 | .highlight .mo { 378 | color: #d19a66 379 | } 380 | .highlight .sb { 381 | color: #48ad00 382 | } 383 | .highlight .sc { 384 | color: #48ad00 385 | } 386 | .highlight .sd { 387 | color: #48ad00 388 | } 389 | .highlight .s2 { 390 | color: #48ad00 391 | } 392 | .highlight .se { 393 | color: #48ad00 394 | } 395 | .highlight .sh { 396 | color: #48ad00 397 | } 398 | .highlight .si { 399 | color: #48ad00 400 | } 401 | .highlight .sx { 402 | color: #48ad00 403 | } 404 | .highlight .sr { 405 | color: #5cc8d6 406 | } 407 | .highlight .s1 { 408 | color: #48ad00 409 | } 410 | .highlight .ss { 411 | color: #5cc8d6 412 | } 413 | .highlight .bp { 414 | color: #ffa600 415 | } 416 | .highlight .vc { 417 | color: #ffa600 418 | } 419 | .highlight .vg { 420 | color: #ffa600 421 | } 422 | .highlight .vi { 423 | color: #e06c75 424 | } 425 | .highlight .il { 426 | color: #d19a66 427 | } 428 | .highlight .gu { 429 | color: #75715e 430 | } 431 | .highlight .gd { 432 | color: #f92672 433 | } 434 | .highlight .gi { 435 | color: #a6e22e 436 | } 437 | -------------------------------------------------------------------------------- /src/main/resources/html/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Luntic 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | Luntic 18 | 19 | 20 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |

Rest API

31 |

32 | This page describes service's REST API. 33 |

34 | 35 | 81 | 82 |
83 | 84 |

Registering new service

85 |

86 | Creates new record. 87 |

88 | 89 |

Request

90 |

91 | POST [/pathPrefix]/{group} 92 |

93 |
    94 |
  • 95 | pathPrefix - common path prefix, which was set (default value - /) at the start of Luntic program; 96 |
  • 97 |
  • 98 | group - name of the registering application group. 99 |
  • 100 |
101 | 102 |

Response

103 |

104 | As a result of the request we get a response: 105 |

106 | 107 |
    108 |
  • 109 | Code: 201 110 |
  • 111 |
  • 112 | Headers: 113 |
      114 |
    • 115 | Location: [/pathPrefix]/{group}/{instanceId} 116 |
    • 117 |
    • 118 | X-Expired-Time: {int_seconds_or_zero_if_disabled} 119 |
    • 120 |
    121 |
  • 122 |
  • 123 | Content type: application/json 124 |
  • 125 |
  • 126 | JSON fields: 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 |
    Field   Optional   Description
    idnogenerated record id
    groupnothe group name you set
    creatednothe time you registered
    modifiednothe time you last accessed the record
    metayesif you send JSON in request, we get it back in that field
    161 |
  • 162 |
163 | 164 |

Error response

165 |
    166 |
  • 167 | 400 - in case of incorrect group set (absent or contains / sign) 168 |
  • 169 |
170 | 171 |

Examples

172 |

173 | Create simple record: 174 |

175 |
176 |
177 |               
178 |                 $> http -v POST :8080/popa
179 | 
180 |                 POST /popa HTTP/1.1
181 |                 Accept: */*
182 |                 Accept-Encoding: gzip, deflate
183 |                 Connection: keep-alive
184 |                 Content-Length: 0
185 |                 Host: localhost:8080
186 | 
187 | 
188 |                 HTTP/1.1 201 Created
189 |                 Content-Length: 124
190 |                 Content-Type: application/json
191 |                 Location: /popa/597298af0937867200000001
192 | 
193 |                 {
194 |                     "created": "2017-07-22T03:13:35+03:00",
195 |                     "group": "popa",
196 |                     "id": "597298af0937867200000001",
197 |                     "modified": "2017-07-22T03:13:35+03:00"
198 |                 }
199 |               
200 |             
201 |
202 | 203 |

204 | Create record with attached metadata: 205 |

206 |
207 |
208 |               
209 |                 $> http -v POST :8080/popa one=1 two=2
210 | 
211 |                 POST /popa HTTP/1.1
212 |                 Accept: application/json, */*
213 |                 Accept-Encoding: gzip, deflate
214 |                 Connection: keep-alive
215 |                 Content-Length: 24
216 |                 Content-Type: application/json
217 |                 Host: localhost:8080
218 | 
219 |                 {
220 |                     "one": "1",
221 |                     "two": "2"
222 |                 }
223 | 
224 | 
225 |                 HTTP/1.1 201 Created
226 |                 Content-Length: 154
227 |                 Content-Type: application/json
228 |                 Location: /popa/5972a20d5b31ed7400000001
229 | 
230 |                 {
231 |                     "created": "2017-07-22T03:53:33+03:00",
232 |                     "group": "popa",
233 |                     "id": "5972a20d5b31ed7400000001",
234 |                     "meta": {
235 |                         "one": "1",
236 |                         "two": "2"
237 |                     },
238 |                     "modified": "2017-07-22T03:53:33+03:00"
239 |                 }
240 |               
241 |             
242 |
243 | 244 |

Retrieve a service(s)

245 |

246 | Returns all or specific records on the server. 247 |

248 | 249 |

Request

250 |

251 | Get all groups and records: 252 |

253 |

254 | GET [/pathPrefix]/ 255 |

256 | 257 |

258 | Get all group's records: 259 |

260 |

261 | GET [/pathPrefix]/{group} 262 |

263 | 264 |

265 | Get only specific record: 266 |

267 |

268 | GET [/pathPrefix]/{group}/{instanceId} 269 |

270 | 271 |
    272 |
  • 273 | pathPrefix - common path prefix, which was set (default value - /) at the start of Luntic program; 274 |
  • 275 |
  • 276 | group - name of the registering application group; 277 |
  • 278 |
  • 279 | instanceId - service instance id. 280 |
  • 281 |
282 | 283 |

Response

284 |

285 | As a result of the request we get a response: 286 |

287 | 288 |
    289 |
  • 290 | Code: 200 291 |
  • 292 |
  • 293 | Content type: application/json 294 |
  • 295 |
  • 296 | JSON fields: 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 |
    Field   Optional   Description
    idnogenerated record id
    groupnothe group name you set
    creatednothe time you registered
    modifiednothe time you last accessed the record
    metayesif you send JSON in request, we get it back in that field
    331 |
  • 332 |
333 | 334 |

Error response

335 |
    336 |
  • 337 | 404 - in case of nonexistent group or instanceId 338 |
  • 339 |
340 | 341 |

Examples

342 | 343 |

344 | Get all records in the service: 345 |

346 |
347 |
348 |               
349 |                 $> http -v :8080/
350 |                 / HTTP/1.1
351 |                 Accept: */*
352 |                 Accept-Encoding: gzip, deflate
353 |                 Connection: keep-alive
354 |                 Host: localhost:8080
355 |                 User-Agent: HTTPie/0.9.9
356 | 
357 | 
358 |                 HTTP/1.1 200 OK
359 |                 Content-Length: 397
360 |                 content-type: application/json
361 | 
362 |                 {
363 |                     "popa": [
364 |                         {
365 |                             "created": "2017-07-23T03:41:51+03:00",
366 |                             "group": "popa",
367 |                             "id": "5973f0cfead3c64a00000001",
368 |                             "modified": "2017-07-23T03:41:51+03:00"
369 |                         },
370 |                         {
371 |                             "created": "2017-07-23T03:41:52+03:00",
372 |                             "group": "popa",
373 |                             "id": "5973f0d0ead3c64a00000002",
374 |                             "modified": "2017-07-23T03:41:52+03:00"
375 |                         }
376 |                     ],
377 |                     "zuul": [
378 |                         {
379 |                             "created": "2017-07-23T03:41:57+03:00",
380 |                             "group": "zuul",
381 |                             "id": "5973f0d5ead3c64a00000003",
382 |                             "modified": "2017-07-23T03:41:57+03:00"
383 |                         }
384 |                     ]
385 |                 }
386 |               
387 |             
388 |
389 | 390 |

391 | Get all records by group name: 392 |

393 |
394 |
395 |               
396 |                 $> http -v :8080/popa
397 |                 GET /popa HTTP/1.1
398 |                 Accept: */*
399 |                 Accept-Encoding: gzip, deflate
400 |                 Connection: keep-alive
401 |                 Host: localhost:8080
402 |                 User-Agent: HTTPie/0.9.9
403 | 
404 | 
405 |                 HTTP/1.1 200 OK
406 |                 Content-Length: 253
407 |                 content-type: application/json
408 | 
409 |                 [
410 |                     {
411 |                         "created": "2017-07-23T03:41:51+03:00",
412 |                         "group": "popa",
413 |                         "id": "5973f0cfead3c64a00000001",
414 |                         "modified": "2017-07-23T03:41:51+03:00"
415 |                     },
416 |                     {
417 |                         "created": "2017-07-23T03:41:52+03:00",
418 |                         "group": "popa",
419 |                         "id": "5973f0d0ead3c64a00000002",
420 |                         "modified": "2017-07-23T03:41:52+03:00"
421 |                     }
422 |                 ]
423 |               
424 |             
425 |
426 | 427 |

428 | Get record by its group and instanceId: 429 |

430 |
431 |
432 |               
433 |                 $> http -v :8080/popa/5973f0cfead3c64a00000001
434 |                 GET /popa/5973f0cfead3c64a00000001 HTTP/1.1
435 |                 Accept: */*
436 |                 Accept-Encoding: gzip, deflate
437 |                 Connection: keep-alive
438 |                 Host: localhost:8080
439 |                 User-Agent: HTTPie/0.9.9
440 | 
441 | 
442 |                 HTTP/1.1 200 OK
443 |                 Content-Length: 125
444 |                 content-type: application/json
445 | 
446 |                 {
447 |                     "created": "2017-07-23T03:41:51+03:00",
448 |                     "group": "popa",
449 |                     "id": "5973f0cfead3c64a00000001",
450 |                     "modified": "2017-07-23T03:41:51+03:00"
451 |                 }
452 |               
453 |             
454 |
455 | 456 |

Update service

457 |

458 | This request, first of all, updates modified time field of the updating record. 459 |

460 | 461 |

Request

462 |

463 | PUT [/pathPrefix]/{group}/{instanceId} 464 |

465 |
    466 |
  • 467 | pathPrefix - common path prefix, which was set (default value - /) at the start of Luntic program; 468 |
  • 469 |
  • 470 | group - name of the registering application group; 471 |
  • 472 |
  • 473 | instanceId - service instance id. 474 |
  • 475 |
476 |

477 | Also, you could send a JSON object with a request. It will be attached to server generated instance in meta field. 478 |

479 | 480 |

Response

481 |

482 | As a result of the request we get a response: 483 |

484 | 485 |
    486 |
  • 487 | Code: 200 488 |
  • 489 |
  • 490 | Content type: application/json 491 |
  • 492 |
  • 493 | JSON fields: 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 |
    Field   Optional   Description
    idnogenerated record id
    groupnothe group name you set
    creatednothe time you registered
    modifiednothe time you last accessed the record
    metayesif you send JSON in request, we get it back in that field
    528 |
  • 529 |
530 | 531 |

Error response

532 |
    533 |
  • 534 | 400 - if neither group nor instanceId are present; 535 | 404 - in case of nonexistent group or instanceId 536 |
  • 537 |
538 | 539 |

Examples

540 |

541 | Regular modified time update: 542 |

543 |
544 |
545 |               
546 |                 http -v PUT :8080/popa/5973f0cfead3c64a00000001
547 |                 PUT /popa/5973f0cfead3c64a00000001 HTTP/1.1
548 |                 Accept: */*
549 |                 Accept-Encoding: gzip, deflate
550 |                 Connection: keep-alive
551 |                 Content-Length: 0
552 |                 Host: localhost:8080
553 |                 User-Agent: HTTPie/0.9.9
554 | 
555 | 
556 |                 HTTP/1.1 200 OK
557 |                 Content-Length: 125
558 |                 content-type: application/json
559 | 
560 |                 {
561 |                     "created": "2017-07-23T03:41:51+03:00",
562 |                     "group": "popa",
563 |                     "id": "5973f0cfead3c64a00000001",
564 |                     "modified": "2017-07-23T03:46:22+03:00"
565 |                 }
566 |               
567 |             
568 |
569 | 570 |

571 | Update with attaching new meta field value: 572 |

573 |
574 |
575 |               
576 |                 http -v PUT :8080/popa/5973f0cfead3c64a00000001 name=Artem
577 |                 PUT /popa/5973f0cfead3c64a00000001 HTTP/1.1
578 |                 Accept: application/json, */*
579 |                 Accept-Encoding: gzip, deflate
580 |                 Connection: keep-alive
581 |                 Content-Length: 17
582 |                 Content-Type: application/json
583 |                 Host: localhost:8080
584 |                 User-Agent: HTTPie/0.9.9
585 | 
586 |                 {
587 |                     "name": "Artem"
588 |                 }
589 | 
590 |                 HTTP/1.1 200 OK
591 |                 Content-Length: 149
592 |                 content-type: application/json
593 | 
594 |                 {
595 |                     "created": "2017-07-23T03:41:51+03:00",
596 |                     "group": "popa",
597 |                     "id": "5973f0cfead3c64a00000001",
598 |                     "meta": {
599 |                         "name": "Artem"
600 |                     },
601 |                     "modified": "2017-07-23T03:47:28+03:00"
602 |                 }
603 |               
604 |             
605 |
606 | 607 |

Removes a service

608 |

609 | Deletes the service from the services. 610 |

611 | 612 |

Request

613 |

614 | DELETE [/pathPrefix]/{group}/{instanceId} 615 |

616 |
    617 |
  • 618 | pathPrefix - common path prefix, which was set (default value - /) at the start of Luntic program; 619 |
  • 620 |
  • 621 | group - name of the registering application group; 622 |
  • 623 |
  • 624 | instanceId - service instance id. 625 |
  • 626 |
627 | 628 |

Response

629 |

630 | As a result of the request we get a response: 631 |

632 |
    633 |
  • 634 | Code: 204 635 |
  • 636 |
  • 637 | No Content 638 |
  • 639 |
640 | 641 |

Error response

642 |
    643 |
  • 644 | 400 - if neither group nor instanceId are present; 645 | 404 - in case of nonexistent group or instanceId 646 |
  • 647 |
648 | 649 |

Examples

650 |
651 |
652 |               
653 |                 $> http -v DELETE :8080/popa/5972a20d5b31ed7400000001
654 |                 DELETE /popa/5973e2c95d89804600000007 HTTP/1.1
655 |                 Accept: */*
656 |                 Accept-Encoding: gzip, deflate
657 |                 Connection: keep-alive
658 |                 Content-Length: 0
659 |                 Host: localhost:8080
660 | 
661 | 
662 |                 HTTP/1.1 204 No Content
663 |                 Content-Length: 0
664 |               
665 |             
666 |
667 | 668 |
669 |
670 |
671 |
672 | 673 |
674 | Copyright 2017 Artem Labazin / 675 | GitHub 676 |
677 | 678 | 679 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Luntic 3 | 4 | A lightweight REST in-memory discovery service. 5 | 6 | Features: 7 | 8 | * periodical task for removing expired records; 9 | 10 | * simple dashboard in web browser. 11 | 12 | The service was inspired by [Eureka](https://github.com/Netflix/eureka) web service and it uses for registration and locating services in your environment. 13 | 14 | It uses REST JSON-based API for simple integration. 15 | 16 | ## Contents 17 | 18 | - [Getting Started](#getting-started) 19 | - [Docker](#docker) 20 | - [API](#api) 21 | - [Registering new service](#registering-new-service) 22 | - [Retrieve a service(s)](#retrieve-services) 23 | - [Update service](#update-service) 24 | - [Remove service](#remove-service) 25 | - [Development](#development) 26 | - [Prerequisites](#prerequisites) 27 | - [Building](#building) 28 | - [Running the tests](#running-the-tests) 29 | - [Built With](#built-with) 30 | - [Changelog](#changelog) 31 | - [Contributing](#contributing) 32 | - [Versioning](#versioning) 33 | - [Authors](#authors) 34 | - [License](#license) 35 | 36 | ## Getting Started 37 | 38 | Start the Luntic discovery server: 39 | 40 | ```bash 41 | $> luntic 42 | 43 | __ __ _ 44 | / / __ __ ____ / /_ (_)_____ 45 | / / / / / // __ \ / __// // ___/ 46 | / /___/ /_/ // / / // /_ / // /__ 47 | /_____/\__,_//_/ /_/ \__//_/ \___/ 48 | 49 | I was born! 50 | 51 | v1.1.0 52 | Copyright (c) by Artem Labazin 53 | 54 | REST requests are serviced on: http://0.0.0.0:8080/ 55 | 56 | ``` 57 | 58 | If you need to launch Luntic on different port, with specific path prefix, debug access logs or public net address, you are able to set it: 59 | 60 | ```bash 61 | $> luntic --debug --port=9999 --path-prefix=/register localhost 62 | 63 | __ __ _ 64 | / / __ __ ____ / /_ (_)_____ 65 | / / / / / // __ \ / __// // ___/ 66 | / /___/ /_/ // / / // /_ / // /__ 67 | /_____/\__,_//_/ /_/ \__//_/ \___/ 68 | 69 | I was born! 70 | 71 | v1.1.0 72 | Copyright (c) by Artem Labazin 73 | 74 | REST requests are serviced on: http://localhost:9999/register 75 | 76 | 2017-07-22T03:20:45+03:00 -- POST /register/popa 77 | 2017-07-22T03:21:12+03:00 -- GET /register 78 | 2017-07-22T03:21:28+03:00 -- DELETE /register/popa/59729a5d8b7df47200000001 79 | 80 | ``` 81 | 82 | We could also start a simple web browser dashboard on separate port: 83 | 84 | ```bash 85 | $> luntic --dashboard:9876 86 | 87 | __ __ _ 88 | / / __ __ ____ / /_ (_)_____ 89 | / / / / / // __ \ / __// // ___/ 90 | / /___/ /_/ // / / // /_ / // /__ 91 | /_____/\__,_//_/ /_/ \__//_/ \___/ 92 | 93 | I was born! 94 | 95 | v1.1.0 96 | Copyright (c) by Artem Labazin 97 | 98 | REST requests are serviced on: http://0.0.0.0:8080/ 99 | Dashboard is available on: http://0.0.0.0:9876/ 100 | 101 | ``` 102 | 103 | Open the link [http://localhost:9876](http://localhost:9876) in your web browser and you could see something like this: 104 | 105 | ![home page](https://github.com/xxlabaza/luntic/blob/master/images/home.png?raw=true) 106 | 107 | And see group info: 108 | 109 | ![group info](https://github.com/xxlabaza/luntic/blob/master/images/group.png?raw=true) 110 | 111 | Also there is a API page: 112 | 113 | ![api page](https://github.com/xxlabaza/luntic/blob/master/images/api.png?raw=true) 114 | 115 | To see all available switches and keys, type the following: 116 | 117 | ```bash 118 | $> luntic --help 119 | 120 | Usage: luntic [OPTIONS] [LISTENING_ADDRESS] 121 | 122 | A lightweight REST in-memory discovery service 123 | 124 | Options: 125 | -p:PORT --port=PORT sets listening port 126 | default: 8080 127 | --path-prefix=PATH sets server's endpoints path prefix 128 | default: '/' 129 | --heartbeat=SECONDS sets heartbeat service cleaner in seconds, 130 | if it set to 0 - turn off heartbeat scheduler 131 | default: 0s 132 | --dashboard=PORT setups a simple web browser-oriented dashboard 133 | for services monitoring 134 | default: turned off 135 | -d --debug turn on debug mode 136 | -v --version prints program's version 137 | -h --help prints this help menu 138 | 139 | ``` 140 | 141 | After starting Luntic server you could register your first app via REST API. 142 | I am using [HTTPie](https://httpie.org) for request calls, but you can do it with cURL or [Postman](https://www.getpostman.com). 143 | 144 | Registering a new app, which has *popa* group name: 145 | 146 | ```bash 147 | $> http -v POST :8080/popa 148 | POST /popa HTTP/1.1 149 | Accept: */* 150 | Accept-Encoding: gzip, deflate 151 | Connection: keep-alive 152 | Content-Length: 0 153 | Host: localhost:8080 154 | User-Agent: HTTPie/0.9.9 155 | 156 | 157 | HTTP/1.1 201 Created 158 | Content-Length: 124 159 | content-type: application/json 160 | location: /popa/597298af0937867200000001 161 | x-expired-time: 0 162 | 163 | { 164 | "created": "2017-07-22T03:13:35+03:00", 165 | "group": "popa", 166 | "id": "597298af0937867200000001", 167 | "modified": "2017-07-22T03:13:35+03:00" 168 | } 169 | 170 | ``` 171 | 172 | As we can see, we have created a new record in **popa** application group. The server have generated the instance id **597298af0937867200000001**, creation time and last modified time fields. 173 | 174 | We are also able to attach our own JSON object to a record in **meta** field during its creation: 175 | 176 | ```bash 177 | $> http -v POST :8080/popa one=1 two=2 178 | POST /popa HTTP/1.1 179 | Accept: application/json, */* 180 | Accept-Encoding: gzip, deflate 181 | Connection: keep-alive 182 | Content-Length: 24 183 | Content-Type: application/json 184 | Host: localhost:8080 185 | User-Agent: HTTPie/0.9.9 186 | 187 | { 188 | "one": "1", 189 | "two": "2" 190 | } 191 | 192 | HTTP/1.1 201 Created 193 | Content-Length: 154 194 | content-type: application/json 195 | location: /popa/5972a20d5b31ed7400000001 196 | x-expired-time: 0 197 | 198 | { 199 | "created": "2017-07-22T03:53:33+03:00", 200 | "group": "popa", 201 | "id": "5972a20d5b31ed7400000001", 202 | "meta": { 203 | "one": "1", 204 | "two": "2" 205 | }, 206 | "modified": "2017-07-22T03:53:33+03:00" 207 | } 208 | 209 | ``` 210 | 211 | To get a just created record - we need to use a path from **Location** header in creation reponse: 212 | 213 | ```bash 214 | $> http -v :8080/popa/5972a2e54396247500000001 215 | GET /popa/5972a2e54396247500000001 HTTP/1.1 216 | Accept: */* 217 | Accept-Encoding: gzip, deflate 218 | Connection: keep-alive 219 | Host: localhost:8080 220 | User-Agent: HTTPie/0.9.9 221 | 222 | 223 | HTTP/1.1 200 OK 224 | Content-Length: 154 225 | content-type: application/json 226 | 227 | { 228 | "created": "2017-07-22T03:53:33+03:00", 229 | "group": "popa", 230 | "id": "5972a20d5b31ed7400000001", 231 | "meta": { 232 | "one": "1", 233 | "two": "2" 234 | }, 235 | "modified": "2017-07-22T03:53:33+03:00" 236 | } 237 | 238 | ``` 239 | 240 | Also, we could get all available records within one group name: 241 | 242 | ```bash 243 | $> http -v :8080/popa 244 | GET /popa HTTP/1.1 245 | Accept: */* 246 | Accept-Encoding: gzip, deflate 247 | Connection: keep-alive 248 | Host: localhost:8080 249 | User-Agent: HTTPie/0.9.9 250 | 251 | 252 | HTTP/1.1 200 OK 253 | Content-Length: 282 254 | content-type: application/json 255 | 256 | [ 257 | { 258 | "created": "2017-07-22T03:13:35+03:00", 259 | "group": "popa", 260 | "id": "597298af0937867200000001", 261 | "modified": "2017-07-22T03:13:35+03:00" 262 | }, 263 | { 264 | "created": "2017-07-22T03:53:33+03:00", 265 | "group": "popa", 266 | "id": "5972a20d5b31ed7400000001", 267 | "meta": { 268 | "one": "1", 269 | "two": "2" 270 | }, 271 | "modified": "2017-07-22T03:53:33+03:00" 272 | } 273 | ] 274 | 275 | ``` 276 | 277 | Or, we can get all data in one object - **group** -> **instances**: 278 | 279 | ```bash 280 | $> http -v :8080/ 281 | GET / HTTP/1.1 282 | Accept: */* 283 | Accept-Encoding: gzip, deflate 284 | Connection: keep-alive 285 | Host: localhost:8080 286 | User-Agent: HTTPie/0.9.9 287 | 288 | 289 | HTTP/1.1 200 OK 290 | Content-Length: 426 291 | content-type: application/json 292 | 293 | { 294 | "popa": [ 295 | { 296 | "created": "2017-07-22T03:13:35+03:00", 297 | "group": "popa", 298 | "id": "597298af0937867200000001", 299 | "modified": "2017-07-22T03:13:35+03:00" 300 | }, 301 | { 302 | "created": "2017-07-22T03:53:33+03:00", 303 | "group": "popa", 304 | "id": "5972a20d5b31ed7400000001", 305 | "meta": { 306 | "one": "1", 307 | "two": "2" 308 | }, 309 | "modified": "2017-07-22T03:53:33+03:00" 310 | } 311 | ], 312 | "zuul": [ 313 | { 314 | "created": "2017-07-22T04:03:26+03:00", 315 | "group": "zuul", 316 | "id": "5972a45e4396247500000003", 317 | "modified": "2017-07-22T04:03:26+03:00" 318 | } 319 | ] 320 | } 321 | ``` 322 | 323 | To update last **modified** time you could type this: 324 | 325 | ```bash 326 | $> http -v PUT :8080/popa/5972a20d5b31ed7400000001 327 | PUT /popa/5972a20d5b31ed7400000001 HTTP/1.1 328 | Accept: */* 329 | Accept-Encoding: gzip, deflate 330 | Connection: keep-alive 331 | Content-Length: 0 332 | Host: localhost:8080 333 | User-Agent: HTTPie/0.9.9 334 | 335 | 336 | HTTP/1.1 200 OK 337 | Content-Length: 154 338 | content-type: application/json 339 | 340 | { 341 | "created": "2017-07-22T03:53:33+03:00", 342 | "group": "popa", 343 | "id": "5972a20d5b31ed7400000001", 344 | "meta": { 345 | "one": "1", 346 | "two": "2" 347 | }, 348 | "modified": "2017-07-22T04:10:42+03:00" 349 | } 350 | 351 | ``` 352 | 353 | Why do we want to update last modified time? Luntic can be started with **--heartbeat=SECONDS** switch, which enables scheduled task for periodical removing expired instances in groups. So, with this switch you need to update modified time, otherwise it removes. By default this scheduled task is disabled. 354 | 355 | With **PUT** method you could also change **meta** field: 356 | 357 | ```bash 358 | $> http -v PUT :8080/popa/5972a20d5b31ed7400000001 greeting="Hello world" one=1 two=2 359 | PUT /popa/5972a20d5b31ed7400000001 HTTP/1.1 360 | Accept: application/json, */* 361 | Accept-Encoding: gzip, deflate 362 | Connection: keep-alive 363 | Content-Length: 51 364 | Content-Type: application/json 365 | Host: localhost:8080 366 | User-Agent: HTTPie/0.9.9 367 | 368 | { 369 | "greeting": "Hello world", 370 | "one": "1", 371 | "two": "2" 372 | } 373 | 374 | HTTP/1.1 200 OK 375 | Content-Length: 179 376 | content-type: application/json 377 | 378 | { 379 | "created": "2017-07-22T03:53:33+03:00", 380 | "group": "popa", 381 | "id": "5972a20d5b31ed7400000001", 382 | "meta": { 383 | "greeting": "Hello world", 384 | "one": "1", 385 | "two": "2" 386 | }, 387 | "modified": "2017-07-22T04:12:16+03:00" 388 | } 389 | 390 | ``` 391 | 392 | And at last, we want to remove the record: 393 | 394 | ```bash 395 | $> http -v DELETE :8080/popa/5972a20d5b31ed7400000001 396 | DELETE /popa/5972a20d5b31ed7400000001 HTTP/1.1 397 | Accept: */* 398 | Accept-Encoding: gzip, deflate 399 | Connection: keep-alive 400 | Content-Length: 0 401 | Host: localhost:8080 402 | User-Agent: HTTPie/0.9.9 403 | 404 | 405 | HTTP/1.1 204 No Content 406 | Content-Length: 0 407 | 408 | ``` 409 | 410 | ## Docker 411 | 412 | You also are able to use already prepared [Docker image](https://hub.docker.com/r/xxlabaza/luntic/): 413 | 414 | ```bash 415 | $> docker run \ 416 | -p 8080:8080 -p 9876:9876 \ 417 | xxlabaza/luntic:1.1.0 \ 418 | --debug --dashboard:9876 419 | ``` 420 | 421 | ## API 422 | 423 | ### Registering new service 424 | 425 | Creates new record. 426 | 427 | * **Request** 428 | 429 | **POST** [/pathPrefix]/{group} 430 | 431 | `pathPrefix` - common path prefix, which was set (default value - **/**) at the start of Luntic program; 432 | 433 | `group` - name of the registering application group. 434 | 435 | Examples: 436 | 437 | * POST /popa - we didn't set `pathPrefix` (it is optional) at start time and set `group` in this request as **popa**; 438 | 439 | * POST /api/popa - we set `pathPrefix` at start time and use it in the request (**api**), also we set `group` (**popa**). 440 | 441 | Also, you could send a `JSON` object with a request. It will be attached to server generated instance in `meta` field. 442 | 443 | * **Success Response:** 444 | 445 | As a result of the request we get a response: 446 | 447 | **Code:** 201 448 | 449 | **Headers:** 450 | 451 | * Location: [/pathPrefix]/{group}/{instanceId} 452 | 453 | * X-Expired-Time: 454 | 455 | **Content type:** application/json 456 | 457 | **JSON fields:** 458 | 459 | | Field name | Optional | Description | 460 | | ------------ | -------- | ----------------------------------------------------------- | 461 | | **id** | no | generated record id | 462 | | **group** | no | the group name you set | 463 | | **created** | no | the time you registered | 464 | | **modified** | no | the time you last accessed the record | 465 | | **meta** | yes | if you send `JSON` in request, we get it back in that field | 466 | 467 | > **IMPORTANT:** Take a look at `X-Expired-Time` header - if it is not `0` value, your record expires after that amount of second. To prevent removing your instance record - make a `PUT` request within this timeout. 468 | 469 | * **Error Response:** 470 | 471 | **400** - in case of incorrect group set (absent or contains */* sign) 472 | 473 | * **Examples:** 474 | 475 | ```bash 476 | $> http -v POST :8080/popa 477 | 478 | POST /popa HTTP/1.1 479 | Accept: */* 480 | Accept-Encoding: gzip, deflate 481 | Connection: keep-alive 482 | Content-Length: 0 483 | Host: localhost:8080 484 | 485 | 486 | HTTP/1.1 201 Created 487 | Content-Length: 124 488 | Content-Type: application/json 489 | Location: /popa/597298af0937867200000001 490 | 491 | { 492 | "created": "2017-07-22T03:13:35+03:00", 493 | "group": "popa", 494 | "id": "597298af0937867200000001", 495 | "modified": "2017-07-22T03:13:35+03:00" 496 | } 497 | 498 | ``` 499 | 500 | ```bash 501 | $> http -v POST :8080/popa one=1 two=2 502 | 503 | POST /popa HTTP/1.1 504 | Accept: application/json, */* 505 | Accept-Encoding: gzip, deflate 506 | Connection: keep-alive 507 | Content-Length: 24 508 | Content-Type: application/json 509 | Host: localhost:8080 510 | 511 | { 512 | "one": "1", 513 | "two": "2" 514 | } 515 | 516 | 517 | HTTP/1.1 201 Created 518 | Content-Length: 154 519 | Content-Type: application/json 520 | Location: /popa/5972a20d5b31ed7400000001 521 | 522 | { 523 | "created": "2017-07-22T03:53:33+03:00", 524 | "group": "popa", 525 | "id": "5972a20d5b31ed7400000001", 526 | "meta": { 527 | "one": "1", 528 | "two": "2" 529 | }, 530 | "modified": "2017-07-22T03:53:33+03:00" 531 | } 532 | 533 | ``` 534 | 535 | ### Retrieve services 536 | 537 | Returns all or specific records on the server. 538 | 539 | * **Request** 540 | 541 | Get all `groups` and records: 542 | 543 | **GET** [/pathPrefix]/ 544 | 545 | Get all `group's` records: 546 | 547 | **GET** [/pathPrefix]/{group} 548 | 549 | Get only specific record: 550 | 551 | **GET** [/pathPrefix]/{group}/{instanceId} 552 | 553 | `pathPrefix` - common path prefix, which was set (default value - **/**) at the start of Luntic program; 554 | 555 | `group` - name of the registered application group. 556 | 557 | `instanceId` - service instance id. 558 | 559 | * **Success Response:** 560 | 561 | As a result of the request we get a response: 562 | 563 | **Code:** 200 564 | 565 | **Content type:** application/json 566 | 567 | **Content fields:** 568 | 569 | | Field name | Optional | Description | 570 | | ------------ | -------- | ----------------------------------------------------------- | 571 | | **id** | no | generated record id | 572 | | **group** | no | the group name you set | 573 | | **created** | no | the time you registered time | 574 | | **modified** | no | the time you last accessed the record | 575 | | **meta** | yes | if you send `JSON` in request, we get it back in that field | 576 | 577 | * **Error Response:** 578 | 579 | **404** - in case of nonexistent `group` or `instanceId`. 580 | 581 | * **Examples:** 582 | 583 | Get all records in the services: 584 | 585 | ```bash 586 | $> http -v :8080/ 587 | / HTTP/1.1 588 | Accept: */* 589 | Accept-Encoding: gzip, deflate 590 | Connection: keep-alive 591 | Host: localhost:8080 592 | User-Agent: HTTPie/0.9.9 593 | 594 | 595 | HTTP/1.1 200 OK 596 | Content-Length: 397 597 | content-type: application/json 598 | 599 | { 600 | "popa": [ 601 | { 602 | "created": "2017-07-23T03:41:51+03:00", 603 | "group": "popa", 604 | "id": "5973f0cfead3c64a00000001", 605 | "modified": "2017-07-23T03:41:51+03:00" 606 | }, 607 | { 608 | "created": "2017-07-23T03:41:52+03:00", 609 | "group": "popa", 610 | "id": "5973f0d0ead3c64a00000002", 611 | "modified": "2017-07-23T03:41:52+03:00" 612 | } 613 | ], 614 | "zuul": [ 615 | { 616 | "created": "2017-07-23T03:41:57+03:00", 617 | "group": "zuul", 618 | "id": "5973f0d5ead3c64a00000003", 619 | "modified": "2017-07-23T03:41:57+03:00" 620 | } 621 | ] 622 | } 623 | ``` 624 | 625 | Get all records by *group* name: 626 | 627 | ```bash 628 | $> http -v :8080/popa 629 | GET /popa HTTP/1.1 630 | Accept: */* 631 | Accept-Encoding: gzip, deflate 632 | Connection: keep-alive 633 | Host: localhost:8080 634 | User-Agent: HTTPie/0.9.9 635 | 636 | 637 | HTTP/1.1 200 OK 638 | Content-Length: 253 639 | content-type: application/json 640 | 641 | [ 642 | { 643 | "created": "2017-07-23T03:41:51+03:00", 644 | "group": "popa", 645 | "id": "5973f0cfead3c64a00000001", 646 | "modified": "2017-07-23T03:41:51+03:00" 647 | }, 648 | { 649 | "created": "2017-07-23T03:41:52+03:00", 650 | "group": "popa", 651 | "id": "5973f0d0ead3c64a00000002", 652 | "modified": "2017-07-23T03:41:52+03:00" 653 | } 654 | ] 655 | ``` 656 | 657 | Get record by its *group* and *instanceId*: 658 | 659 | ```bash 660 | $> http -v :8080/popa/5973f0cfead3c64a00000001 661 | GET /popa/5973f0cfead3c64a00000001 HTTP/1.1 662 | Accept: */* 663 | Accept-Encoding: gzip, deflate 664 | Connection: keep-alive 665 | Host: localhost:8080 666 | User-Agent: HTTPie/0.9.9 667 | 668 | 669 | HTTP/1.1 200 OK 670 | Content-Length: 125 671 | content-type: application/json 672 | 673 | { 674 | "created": "2017-07-23T03:41:51+03:00", 675 | "group": "popa", 676 | "id": "5973f0cfead3c64a00000001", 677 | "modified": "2017-07-23T03:41:51+03:00" 678 | } 679 | ``` 680 | 681 | ### Update service 682 | 683 | This request, first of all, updates `modified` time field of the updating record. 684 | 685 | * **Request** 686 | 687 | **PUT** [/pathPrefix]/{group}/{instanceId} 688 | 689 | `pathPrefix` - common path prefix, which was set (default value - **/**) at the start of Luntic program; 690 | 691 | `group` - name of the registered application group. 692 | 693 | `instanceId` - service instance id for updating. 694 | 695 | Also, you could send a `JSON` object with a request. It will be attached to server generated instance in `meta` field. 696 | 697 | * **Success Response:** 698 | 699 | As a result of the request we get a response: 700 | 701 | **Code:** 200 702 | 703 | **Content type:** JSON 704 | 705 | **Content fields:** 706 | 707 | | Field name | Optional | Description | 708 | | ------------ | -------- | ----------------------------------------------------------- | 709 | | **id** | no | generated record id | 710 | | **group** | no | the group name you set | 711 | | **created** | no | the time you registered time | 712 | | **modified** | no | the time you last accessed the record | 713 | | **meta** | yes | if you send `JSON` in request, we get it back in that field | 714 | 715 | * **Error Response:** 716 | 717 | **400** - if not `group` or `instanceId` are present; 718 | 719 | **404** - in case of nonexistent `group` or `instanceId`. 720 | 721 | * **Examples:** 722 | 723 | Regular *modified* time update: 724 | 725 | ```bash 726 | http -v PUT :8080/popa/5973f0cfead3c64a00000001 727 | PUT /popa/5973f0cfead3c64a00000001 HTTP/1.1 728 | Accept: */* 729 | Accept-Encoding: gzip, deflate 730 | Connection: keep-alive 731 | Content-Length: 0 732 | Host: localhost:8080 733 | User-Agent: HTTPie/0.9.9 734 | 735 | 736 | HTTP/1.1 200 OK 737 | Content-Length: 125 738 | content-type: application/json 739 | 740 | { 741 | "created": "2017-07-23T03:41:51+03:00", 742 | "group": "popa", 743 | "id": "5973f0cfead3c64a00000001", 744 | "modified": "2017-07-23T03:46:22+03:00" 745 | } 746 | ``` 747 | 748 | Update with attaching new *meta* field value: 749 | 750 | ```bash 751 | http -v PUT :8080/popa/5973f0cfead3c64a00000001 name=Artem 752 | PUT /popa/5973f0cfead3c64a00000001 HTTP/1.1 753 | Accept: application/json, */* 754 | Accept-Encoding: gzip, deflate 755 | Connection: keep-alive 756 | Content-Length: 17 757 | Content-Type: application/json 758 | Host: localhost:8080 759 | User-Agent: HTTPie/0.9.9 760 | 761 | { 762 | "name": "Artem" 763 | } 764 | 765 | HTTP/1.1 200 OK 766 | Content-Length: 149 767 | content-type: application/json 768 | 769 | { 770 | "created": "2017-07-23T03:41:51+03:00", 771 | "group": "popa", 772 | "id": "5973f0cfead3c64a00000001", 773 | "meta": { 774 | "name": "Artem" 775 | }, 776 | "modified": "2017-07-23T03:47:28+03:00" 777 | } 778 | ``` 779 | 780 | ### Remove service 781 | 782 | Deletes the service from the services. 783 | 784 | * **Request** 785 | 786 | **DELETE** [/pathPrefix]/{group}/{instanceId} 787 | 788 | `pathPrefix` - common path prefix, which was set (default value - **/**) at the start of Luntic program; 789 | 790 | `group` - name of the registered application group. 791 | 792 | `instanceId` - service instance id for removing. 793 | 794 | * **Success Response:** 795 | 796 | As a result of the request we get a response: 797 | 798 | **Code:** 204 799 | 800 | **No Content** 801 | 802 | * **Error Response:** 803 | 804 | **400** - if not `group` or `instanceId` are present; 805 | 806 | **404** - in case of nonexistent `group` or `instanceId`. 807 | 808 | * **Examples:** 809 | 810 | ```bash 811 | $> http -v DELETE :8080/popa/5972a20d5b31ed7400000001 812 | DELETE /app/popa/5973e2c95d89804600000007 HTTP/1.1 813 | Accept: */* 814 | Accept-Encoding: gzip, deflate 815 | Connection: keep-alive 816 | Content-Length: 0 817 | Host: localhost:8080 818 | 819 | 820 | HTTP/1.1 204 No Content 821 | Content-Length: 0 822 | ``` 823 | 824 | ## Development 825 | 826 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. 827 | 828 | ### Prerequisites 829 | 830 | For building the project you need only a [Nim](https://nim-lang.org) compiler ([Windows](https://nim-lang.org/install_windows.html) or [OSX/Unix](https://nim-lang.org/install_unix.html)). 831 | 832 | > **IMPORTANT:** Luntic requires Nim version **0.17.0** 833 | 834 | And, of course, you need to clone Luntic from GitHub: 835 | 836 | ```bash 837 | $> git clone https://github.com/xxlabaza/luntic 838 | $> cd luntic 839 | ``` 840 | 841 | ### Building 842 | 843 | For building routine automation, I am using [config.nims](./config.nims) file. It contains all needed tasks described in **Nim** language. 844 | 845 | To build the Luntic project, do the following: 846 | 847 | ```bash 848 | $> nim build 849 | ... 850 | Hint: operation successful (52249 lines compiled; 4.124 sec total; 106.934MiB peakmem; Debug Build) [SuccessX] 851 | ``` 852 | 853 | If you need to build a release (less output binnary file size): 854 | 855 | ```bash 856 | $> nim build release 857 | ``` 858 | 859 | To check, what everything is fine, type the nex command: 860 | 861 | ```bash 862 | $> build/target/luntic -v 863 | v1.1.0 864 | ``` 865 | 866 | To build a docker image: 867 | 868 | ```bash 869 | $> nim docker 870 | ``` 871 | 872 | ### Running the tests 873 | 874 | To run the project's test, do the following: 875 | 876 | ```bash 877 | $> nim test 878 | ... 879 | [OK] Parsing request parts 880 | ``` 881 | 882 | Also, if you build a release, the tests launch automatically. 883 | 884 | ## Built With 885 | 886 | * [Nim](https://nim-lang.org) - is a systems and applications programming language 887 | 888 | ## Changelog 889 | 890 | To see what has changed in recent versions of Luntic, see the [changelog](./CHANGELOG.md) file. 891 | 892 | ## Contributing 893 | 894 | Please read [contributing](./CONTRIBUTING.md) file for details on my code of conduct, and the process for submitting pull requests to me. 895 | 896 | ## Versioning 897 | 898 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/xxlabaza/luntic/tags). 899 | 900 | ## Authors 901 | 902 | * **Artem Labazin** - the main creator and developer 903 | 904 | ## License 905 | 906 | This project is licensed under the Apache License 2.0 License - see the [license](./LICENSE) file for details 907 | --------------------------------------------------------------------------------