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
Aaron Pritzlaff
committed
Jan 3, 2022
1 parent
9e2d13e
commit e7fe50a
Showing
49 changed files
with
205 additions
and
22,748 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# code template | ||
# Code Template | ||
![build](https://github.com/aaronp/code-template/actions/workflows/ci.yml/badge.svg) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.aaronp/code-template_3/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.aaronp/code-template_3) | ||
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
An opinionated utility for converting scala scripts into functions which | ||
can work with json. | ||
|
||
Documentation can be found [here](https://aaronp.github.io/code-template/) | ||
Check out the [Documentation](https://aaronp.github.io/code-template/) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This is just a convenience script should anybody want to test locally if they don't have sbt installed | ||
# | ||
# See https://hub.docker.com/r/hseeberger/scala-sbt/ | ||
docker run -it --rm -u sbtuser \ | ||
-w /code \ | ||
-v $(pwd):/code \ | ||
-v $HOME/.ivy2:/home/sbtuser/.ivy2 \ | ||
-v $HOME/.sbt:/home/sbtuser/.sbt \ | ||
-v $HOME/.m2:/home/sbtuser/.m2 \ | ||
hseeberger/scala-sbt:8u222_1.3.5_2.13.1 \ | ||
sbt test |
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,11 +1,49 @@ | ||
# Code Template | ||
### The Way Configuration Is Done Hurts | ||
|
||
To install my project | ||
```scala | ||
libraryDependencies += "com.github.aaronp" % "code-template" % "@VERSION@" | ||
There is a lot of common ceremony/boilerplate in a lot of projects - setting up REST services, or ETL functions, etc. | ||
|
||
This project provides the main components to drive a "black-box" computation - typically which operates on json messages. | ||
|
||
This is a typical software component project life-cycle: | ||
|
||
``` | ||
1. bootstrap a new project (or copy/clone some exististing project) | ||
2. hack around with all the usual stuff (configuration parsing, auth, routing, packaging, ...) | ||
3. finally get to the business logic you wanted to solve | ||
``` | ||
|
||
And then the iterations - with a new feature/behavior, you often have to: | ||
|
||
``` | ||
1. introduce some new property (e.g., perhaps an `app.properties` has a myApp.newFeature.isEnabled = true) | ||
2. change the config parsing (the code which knows how to look for myApp.newFeature.isEnabled) | ||
3. implement some logic based on that configuration | ||
``` | ||
|
||
# Usage | ||
|
||
Imagine we're writing an application which knows how to do efficient, resource-safe batch processing on a stream of data. | ||
|
||
That application might use this library to do something like this: | ||
``` | ||
val compiler = CodeTemplate.newCache[Json, Json]() | ||
``` | ||
|
||
That compiler is a function which takes a string (e.g. some business logic script) and returns the __business logic__ - a function | ||
which takes some input _Context_ and returns the result type (e.g. some Json in this case). | ||
|
||
``` | ||
// in practice, this script wouldn't be hard-coded, but come an application configuration, such as a kubernetes config map, | ||
// a cloud bucket - whatever. | ||
val script : String = """ | ||
val result = input.content.hello.world // <-- here we would implment our business logic - compute a value, call a service, whatever | ||
result.asJson | ||
""" | ||
// at the usage site, that script would be attempted to be compiled (hence the Try) into an Expression, | ||
// which is a function of some 'Context[Input]' into the result type. | ||
// | ||
// here we have normal Json input and Json output: | ||
val compiledResult: Try[Expression[Json, Json]] = compiler(script) | ||
``` | ||
|
||
```scala mdoc | ||
val x = 1 | ||
List(x, x) | ||
``` |
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,6 +1,38 @@ | ||
# Code Template | ||
![build](https://github.com/aaronp/code-template/actions/workflows/ci.yml/badge.svg) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.aaronp/code-template_3/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.aaronp/code-template_3) | ||
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
To install: | ||
```scala | ||
libraryDependencies += "com.github.aaronp" % "code-template" % "0.1.1" | ||
# About - the 'why' idea | ||
|
||
### TL;DR; | ||
|
||
Write [serverless-like](https://en.wikipedia.org/wiki/Serverless_computing) applications which have the ability to actually reach stability. | ||
|
||
That is, just drop-in the business logic script within some applications without having to change those applications. | ||
|
||
Any time we have to create a new app, such as: | ||
* a REST service which can execute some business logic for fixed endpoints | ||
* a steams (kafka, rabbit, whatever) app to do some ETL | ||
* a batch/cron job which can do all the authentication/context prep and then just run some logic | ||
|
||
We have some overhead before we even do anything: | ||
* create a repo | ||
* put in the CI/CD | ||
* documentation | ||
* the SDLC stuff (dev/test/release) | ||
|
||
We should be able to do better - to offer an "insert here" business-logic in a lof our applications. | ||
|
||
To read more, see [here](about.md). | ||
|
||
# Building | ||
|
||
This project is built using [sbt](https://www.scala-sbt.org/): | ||
``` | ||
sbt test | ||
``` | ||
|
||
Otherwise if you want to play around (and have docker installed) for a container-based experience: | ||
``` | ||
./dockerTest.sh | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.