├── .gitignore ├── src ├── index.js ├── ffi.js ├── main.gleam ├── openweathermap.gleam └── cloudflare │ └── worker.gleam ├── bin ├── bundle.sh └── build.js ├── wrangler.toml ├── README.md ├── package.json └── LICENCE /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | node_modules 3 | /.idea/ 4 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { main } from "./main.js"; 2 | main(); 3 | -------------------------------------------------------------------------------- /bin/bundle.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | set -eu 3 | 4 | ./node_modules/.bin/esbuild target/lib/gleam-v0.17-example/index.js --bundle --outfile=target/dist/index.js 5 | -------------------------------------------------------------------------------- /wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "gleam-v0-17-example" 2 | type = "javascript" 3 | zone_id = "" 4 | account_id = "" 5 | route = "" 6 | workers_dev = true 7 | compatibility_date = "2021-09-19" 8 | 9 | [build] 10 | command = "npm run build" 11 | 12 | [build.upload] 13 | format = "service-worker" 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gleam v0.17 serverless example 2 | 3 | An example of Gleam v0.17 running on the CloudFlare Workers serverless platform, 4 | using various Gleam libraries and the openweathermap API. 5 | 6 | This app is running at https://gleam-v0-17-example.lpil.workers.dev. 7 | 8 | If you'd like to try out Gleam on CloudFlare Workers check out this template: 9 | https://github.com/lpil/gleam-cloudflare-worker. 10 | -------------------------------------------------------------------------------- /src/ffi.js: -------------------------------------------------------------------------------- 1 | export function add_fetch_event_listener(handleRequest) { 2 | addEventListener("fetch", (event) => { 3 | event.respondWith(handleRequest(event.request)); 4 | }); 5 | } 6 | 7 | export function response(status, headersList, body) { 8 | let headers = new Headers(); 9 | for (let [k, v] of headersList) headers.append(k, v); 10 | return new Response(body, { 11 | status, 12 | headers, 13 | }); 14 | } 15 | 16 | export function method(request) { 17 | return request.method; 18 | } 19 | 20 | export function url(request) { 21 | return request.url; 22 | } 23 | 24 | export function body(request) { 25 | return request.body; 26 | } 27 | 28 | export function city(request) { 29 | return request.cf.city; 30 | } 31 | 32 | export function country(request) { 33 | return request.cf.country; 34 | } 35 | 36 | export function latitude(request) { 37 | return request.cf.latitude; 38 | } 39 | 40 | export function longitude(request) { 41 | return request.cf.longitude; 42 | } 43 | 44 | export function open_weather_api_key() { 45 | return OPEN_WEATHER_API_KEY; // Injected by CloudFlare Workers secrets 46 | } 47 | -------------------------------------------------------------------------------- /src/main.gleam: -------------------------------------------------------------------------------- 1 | import cloudflare/worker.{Request, Response} 2 | import gleam/javascript/promise.{Promise} 3 | import gleam/string 4 | import gleam/float 5 | import openweathermap 6 | 7 | pub fn main() { 8 | worker.add_fetch_event_listener(handle_fetch) 9 | } 10 | 11 | fn handle_fetch(request: Request) -> Promise(Response) { 12 | let lat = worker.latitude(request) 13 | let lon = worker.longitude(request) 14 | openweathermap.get_temperature(lat, lon) 15 | |> promise.map(fn(temp) { 16 | let body = make_body(worker.city(request), temp) 17 | worker.response(200, [#("x-powered-by", "Gleam")], body) 18 | }) 19 | } 20 | 21 | fn make_body(city: String, temp: Result(Float, Nil)) -> String { 22 | let message = case temp { 23 | Ok(temp) -> { 24 | let temp = float.to_string(temp) 25 | string.concat(["It's ", temp, " degrees celsius in ", city, " right now."]) 26 | } 27 | Error(Nil) -> string.concat(["I think you're currently in ", city, "."]) 28 | } 29 | let body = 30 | string.concat([ 31 | "Hello from Gleam on Cloudflare Workers ✨\n\n", 32 | message, 33 | "\nI hope you're having a great time over there!", 34 | ]) 35 | } 36 | -------------------------------------------------------------------------------- /src/openweathermap.gleam: -------------------------------------------------------------------------------- 1 | //// Getting the temperature of a given location using 2 | //// https://openweathermap.org/. Thanks openweathermap! 3 | 4 | import gleam/javascript/promise.{Promise} 5 | import gleam/dynamic.{DecodeError, Dynamic} 6 | import gleam/http.{Get} 7 | import gleam/result 8 | import gleam/fetch 9 | 10 | pub fn get_temperature(lat: String, lon: String) -> Promise(Result(Float, Nil)) { 11 | let query = [ 12 | #("lat", lat), 13 | #("lon", lon), 14 | #("units", "metric"), 15 | #("appid", api_key()), 16 | ] 17 | http.default_req() 18 | |> http.set_method(Get) 19 | |> http.set_host("api.openweathermap.org") 20 | |> http.set_path("/data/2.5/weather") 21 | |> http.set_query(query) 22 | |> fetch.send 23 | |> promise.then_try(fetch.read_json_body) 24 | |> promise.map(result.nil_error) 25 | |> promise.then_try(fn(response: http.Response(Dynamic)) { 26 | response.body 27 | |> decode_temperature 28 | |> result.nil_error 29 | |> promise.resolve 30 | }) 31 | } 32 | 33 | fn decode_temperature(json: Dynamic) -> Result(Float, DecodeError) { 34 | try main = dynamic.field(json, "main") 35 | try temp = dynamic.field(main, "temp") 36 | dynamic.float(temp) 37 | } 38 | 39 | external fn api_key() -> String = 40 | "./ffi.js" "open_weather_api_key" 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gleam-v0.17-example", 3 | "version": "1.0.0", 4 | "description": "Cloudflare worker Gleam template", 5 | "type": "module", 6 | "author": "Louis Pilfold ", 7 | "license": "Apache-2.0", 8 | "main": "target/dist/index.js", 9 | "scripts": { 10 | "build": "node bin/build.js build && sh bin/bundle.sh", 11 | "test": "node bin/build.js test", 12 | "format": "gleam format", 13 | "uuid": "echo f0bdfd1a39324e26b30f8360a0ba00cd" 14 | }, 15 | "devDependencies": { 16 | "esbuild": "^0.12.24", 17 | "gleam-packages": "file:./target/lib" 18 | }, 19 | "gleamDependencies": [ 20 | { 21 | "name": "gleam_stdlib", 22 | "ref": "main", 23 | "url": "https://github.com/gleam-lang/stdlib.git" 24 | }, 25 | { 26 | "name": "gleam_javascript", 27 | "ref": "main", 28 | "url": "https://github.com/gleam-lang/javascript.git", 29 | "dependencies": [ 30 | "gleam_stdlib" 31 | ] 32 | }, 33 | { 34 | "name": "gleam_http", 35 | "ref": "main", 36 | "url": "https://github.com/gleam-lang/http.git", 37 | "dependencies": [ 38 | "gleam_stdlib" 39 | ] 40 | }, 41 | { 42 | "name": "gleam_fetch", 43 | "ref": "main", 44 | "url": "https://github.com/gleam-lang/fetch.git", 45 | "dependencies": [ 46 | "gleam_stdlib", 47 | "gleam_http", 48 | "gleam_javascript" 49 | ] 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /src/cloudflare/worker.gleam: -------------------------------------------------------------------------------- 1 | import gleam/javascript/promise.{Promise} 2 | 3 | // request: { 4 | // "cf": { 5 | // "clientTcpRtt": 0, 6 | // "longitude": "0", 7 | // "httpProtocol": "HTTP/1.1", 8 | // "tlsCipher": "ECDHE-ECDSA-AES128-GCM-SHA256", 9 | // "continent": "EU", 10 | // "asn": 9105, 11 | // "clientAcceptEncoding": "gzip", 12 | // "country": "GB", 13 | // "tlsClientAuth": { 14 | // "certIssuerDNLegacy": "", 15 | // "certIssuerSKI": "", 16 | // "certSubjectDNRFC2253": "", 17 | // "certSubjectDNLegacy": "", 18 | // "certFingerprintSHA256": "", 19 | // "certNotBefore": "", 20 | // "certSKI": "", 21 | // "certSerial": "", 22 | // "certIssuerDN": "", 23 | // "certVerified": "NONE", 24 | // "certNotAfter": "", 25 | // "certSubjectDN": "", 26 | // "certPresented": "0", 27 | // "certRevoked": "0", 28 | // "certIssuerSerial": "", 29 | // "certIssuerDNRFC2253": "", 30 | // "certFingerprintSHA1": "" 31 | // }, 32 | // "tlsExportedAuthenticator": { 33 | // "clientFinished": "c81fe95f9bca118c571267a8ac34fca5e97d687761b826011990887b869a616f", 34 | // "clientHandshake": "a4371aac55ca9fecb284202a08fb525a3f0461c1d85d91210efd1a1831a19fe9", 35 | // "serverHandshake": "b4544fb4ad5de2da8297dc14afe201c2daacd9e047c06bd0d9b654bf6eb5444d", 36 | // "serverFinished": "5c1e40f421d5013d42d7f78bd886110441f80bcd4884cee79bcae93366dda039" 37 | // }, 38 | // "tlsVersion": "TLSv1.2", 39 | // "colo": "LHR", 40 | // "timezone": "Europe/London", 41 | // "region": "England", 42 | // "requestPriority": "", 43 | // "latitude": "0.60040", 44 | // "city": "London", 45 | // "regionCode": "ENG", 46 | // "postalCode": "LON", 47 | // "edgeRequestKeepAliveStatus": 1 48 | // }, 49 | // "fetcher": {}, 50 | // "redirect": "manual", 51 | // "headers": {}, 52 | // "url": "https://gleam-cloudflare-worker.lpil.workers.dev/", 53 | // "method": "GET", 54 | // "bodyUsed": false, 55 | // "body": null 56 | // } 57 | pub external type Request 58 | 59 | pub external type Response 60 | 61 | pub external fn add_fetch_event_listener( 62 | fn(Request) -> Promise(Response), 63 | ) -> Nil = 64 | "../ffi.js" "add_fetch_event_listener" 65 | 66 | pub external fn response( 67 | status: Int, 68 | headers: List(#(String, String)), 69 | body: String, 70 | ) -> Response = 71 | "../ffi.js" "response" 72 | 73 | pub external fn method(Request) -> String = 74 | "../ffi.js" "method" 75 | 76 | pub external fn url(Request) -> String = 77 | "../ffi.js" "url" 78 | 79 | pub external fn body(Request) -> String = 80 | "../ffi.js" "body" 81 | 82 | pub external fn city(Request) -> String = 83 | "../ffi.js" "city" 84 | 85 | pub external fn country(Request) -> String = 86 | "../ffi.js" "country" 87 | 88 | pub external fn latitude(Request) -> String = 89 | "../ffi.js" "latitude" 90 | 91 | pub external fn longitude(Request) -> String = 92 | "../ffi.js" "longitude" 93 | -------------------------------------------------------------------------------- /bin/build.js: -------------------------------------------------------------------------------- 1 | // Gleam build.js version:2021-09-12 2 | 3 | import { 4 | rm, 5 | stat, 6 | copyFile, 7 | readFile, 8 | mkdir, 9 | access, 10 | readdir, 11 | } from "fs/promises"; 12 | import { resolve, relative, join } from "path"; 13 | import { promisify } from "util"; 14 | import { exec as callbackExec } from "child_process"; 15 | 16 | let exec = promisify(callbackExec); 17 | 18 | export async function build() { 19 | let { name, gleamDependencies } = JSON.parse( 20 | await readFile("./package.json") 21 | ); 22 | 23 | await Promise.all(gleamDependencies.map(clone)); 24 | for (let dep of gleamDependencies) await cachedBuildProject(dep); 25 | 26 | await buildProject({ 27 | name, 28 | root: ".", 29 | includeTests: true, 30 | dependencies: gleamDependencies.map((d) => d.name), 31 | }); 32 | 33 | return { 34 | name, 35 | }; 36 | } 37 | 38 | async function copyJs(name, dir) { 39 | let inDir = join(dir, "src"); 40 | let out = outDir(name); 41 | let files = await readdir(inDir); 42 | files.map(async (file) => { 43 | if (file.endsWith(".js")) { 44 | await copyFile(join(inDir, file), join(out, file)); 45 | } 46 | }); 47 | } 48 | 49 | async function cachedBuildProject(info) { 50 | if (await fileExists(outDir(info.name))) return; 51 | await buildProject(info); 52 | } 53 | 54 | async function buildProject({ name, root, dependencies, includeTests }) { 55 | console.log(`Building ${name}`); 56 | let dir = root || libraryDir(name); 57 | let src = join(dir, "src"); 58 | let test = join(dir, "test"); 59 | let out = outDir(name); 60 | await rm(out, { recursive: true, force: true }); 61 | try { 62 | await exec( 63 | [ 64 | "gleam compile-package", 65 | `--name ${name}`, 66 | "--target javascript", 67 | `--src ${src}`, 68 | includeTests ? `--test ${test}` : "", 69 | `--out ${out}`, 70 | (dependencies || []).map((dep) => `--lib=${outDir(dep)}`).join(" "), 71 | ].join(" ") 72 | ); 73 | } catch (error) { 74 | console.error(error.stderr); 75 | process.exit(1); 76 | } 77 | await copyJs(name, dir); 78 | } 79 | 80 | async function clone({ name, ref, url }) { 81 | let dir = libraryDir(name); 82 | if (await fileExists(dir)) return; 83 | console.log("Cloning", name); 84 | await mkdir(dir, { recursive: true }); 85 | await exec(`git clone --depth=1 --branch="${ref}" "${url}" "${dir}"`); 86 | } 87 | 88 | function libraryDir(name) { 89 | return resolve(join("target", "deps", name)); 90 | } 91 | 92 | function outDir(name) { 93 | return resolve(join("target", "lib", name)); 94 | } 95 | 96 | async function fileExists(path) { 97 | try { 98 | await access(path); 99 | return true; 100 | } catch { 101 | return false; 102 | } 103 | } 104 | 105 | async function test() { 106 | let gleamPackage = await build(); 107 | 108 | console.log("Running tests..."); 109 | 110 | let dir = `target/lib/${gleamPackage.name}`; 111 | let passes = 0; 112 | let failures = 0; 113 | 114 | for await (let path of await getFiles(dir)) { 115 | if (!path.endsWith("_test.js")) continue; 116 | let module = await import(path); 117 | 118 | for await (let fnName of Object.keys(module)) { 119 | if (!fnName.endsWith("_test")) continue; 120 | try { 121 | await module[fnName](); 122 | process.stdout.write(`\u001b[32m.\u001b[0m`); 123 | passes++; 124 | } catch (error) { 125 | let moduleName = "\n" + relative(dir, path).slice(0, -3); 126 | process.stdout.write(`\n❌ ${moduleName}.${fnName}: ${error}\n`); 127 | failures++; 128 | } 129 | } 130 | } 131 | 132 | console.log(` 133 | 134 | ${passes + failures} tests 135 | ${failures} failures`); 136 | process.exit(failures ? 1 : 0); 137 | } 138 | 139 | async function start() { 140 | let { name } = await build(); 141 | let { main } = await import(join(outDir(name), "main.js")); 142 | return main(); 143 | } 144 | 145 | async function getFiles(dir) { 146 | const subdirs = await readdir(dir); 147 | const files = await Promise.all( 148 | subdirs.map(async (subdir) => { 149 | const res = resolve(dir, subdir); 150 | return (await stat(res)).isDirectory() ? getFiles(res) : res; 151 | }) 152 | ); 153 | return files.reduce((a, f) => a.concat(f), []); 154 | } 155 | 156 | async function main() { 157 | switch (process.argv[process.argv.length - 1]) { 158 | case "build": 159 | return await build(); 160 | 161 | case "test": 162 | return await test(); 163 | 164 | case "start": 165 | return await start(); 166 | 167 | default: 168 | console.error(` 169 | Usage: 170 | node bin/build.js test 171 | node bin/build.js build 172 | node bin/build.js start 173 | `); 174 | process.exit(1); 175 | } 176 | } 177 | 178 | main(); 179 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2020, Louis Pilfold . 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | 192 | --------------------------------------------------------------------------------