Last active
June 25, 2019 15:09
-
-
Save ranrubin/ec5960a7014bec5343d58b798305a295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.foo | |
/** A map that holds all constants and data members that can be override when constructing */ | |
consulEnv | |
/** An HttpRest object that handles http requests */ | |
httpHandler | |
def construct(httpObj){ | |
consulEnv = [ | |
ip : '', | |
port: '', | |
base_url: '', | |
debug: false // default value that can be overwritten | |
] | |
httpHandler = httpObj | |
} | |
def getConsulEnv(){ | |
return consulEnv | |
} | |
def mergeMaps(Map baseMap, Map otherMap){ | |
if (!baseMap || !otherMap){ | |
return | |
} | |
otherMap.each{ key, value -> | |
baseMap[key] = value | |
} | |
} | |
def overrideConstants(Map values){ | |
mergeMaps(consulEnv, values) // overriding parameters | |
if (!values.base_url) { // if did not get any pther input from user, constructing it myself by default convention | |
consulEnv.put('base_url', "http://${consulEnv.ip}:${consulEnv.port}/v1") | |
} | |
} | |
def register(String data){ | |
return httpHandler.put("/catalog/register", data) | |
} | |
def store(String key_path, String data){ | |
return httpHandler.put(key_path, data) | |
} | |
def list_nodes(){ | |
return httpHandler.get("/catalog/nodes") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment