Skip to content

Instantly share code, notes, and snippets.

@tosuke
Last active September 30, 2016 16:43
Show Gist options
  • Save tosuke/71ff6d61cdc7f94c379b128370ad4341 to your computer and use it in GitHub Desktop.
Save tosuke/71ff6d61cdc7f94c379b128370ad4341 to your computer and use it in GitHub Desktop.
https://github.com/atnanasi/is-saikou をvibe.dで実装した
// dub --single (kore)で動く
/+ dub.json:
{
"name": "is_saikou",
"dependencies": {
"vibe-d": "~>0.7.28",
},
"versions": [
"VibeDefaultMain"
],
"dflags-ldc":["-disable-linker-strip-dead"]
}
+/
import vibe.d;
shared static this(){
auto router = new URLRouter;
router.registerRestInterface(new MyAPI());
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}
struct IsQuery{
bool result;
string message;
}
@path("/") interface IMyAPI{
//GET /:object/is_saikou
@path("/:object/is_saikou")
@property IsQuery queryIsSaikou(string _object);
}
class MyAPI : IMyAPI{
IsQuery queryIsSaikou(string o){
import std.string, std.regex;
IsQuery a;
if(o.toLower.matchAll(ctRegex!(`thinkpad`)).empty == false){
with(a){
result = true;
message = o ~ " is saikou";
}
}else{
with(a){
result = false;
message = o ~ " is kuso";
}
}
return a;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment