-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
# https://marketplace.visualstudio.com/items?itemName=twineworks.tweakflow | ||
# https://twineworks.github.io/tweakflow/reference.html | ||
# https://twineworks.github.io/tweakflow/modules/std.html#std | ||
|
||
import * as std from "std"; | ||
|
||
# local alias for imported library | ||
alias std.strings as str; | ||
|
||
# Documentation is found in std, i.e. str.starts_with? is in | ||
# https://twineworks.github.io/tweakflow/modules/std.html#strings-starts_with? | ||
# Note that starts_with? returns nil rather than false if a passed in field is nil | ||
|
||
library echopraxia { | ||
|
||
# level: the logging level | ||
# fields: the dictionary of fields | ||
# | ||
function evaluate: (string level, dict fields) -> | ||
fields[:request_remote_addr] == "127.0.0.1"; | ||
fields[:request_remote_addr] != nil && str.starts_with?(fields[:request_remote_addr], "127"); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.restservice; | ||
|
||
import com.tersesystems.echopraxia.Condition; | ||
import com.tersesystems.echopraxia.Logger; | ||
import com.tersesystems.echopraxia.LoggerFactory; | ||
import com.tersesystems.echopraxia.scripting.ScriptCondition; | ||
import com.tersesystems.echopraxia.scripting.ScriptHandle; | ||
import com.tersesystems.echopraxia.scripting.ScriptWatchService; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class Conditions { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(); | ||
|
||
// This should generally be global to the application, as it creates a watcher thread internally | ||
private static final Path scriptDirectory = Paths.get("scripts").toAbsolutePath(); | ||
|
||
// Watch the directory | ||
private static final ScriptWatchService scriptWatchService = new ScriptWatchService(scriptDirectory); | ||
|
||
private static final ScriptHandle scriptHandle = scriptWatchService.watchScript( | ||
scriptDirectory.resolve("condition.tf"), e -> logger.error(e.getMessage(), e)); | ||
|
||
// Creates a condition from a script and re-evaluates it whenever the script changes | ||
public static final Condition debugCondition = ScriptCondition.create(scriptHandle); | ||
} |
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