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
const fetch = require('node-fetch') | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
/** | |
* Fetch and log a request | |
* @param {Request} request | |
*/ |
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
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/first-key" \ | |
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ | |
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \ |
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
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/first-key" \ | |
-X PUT \ | |
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ | |
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \ | |
--data 'My first value!' |
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
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces" \ | |
-X POST \ | |
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ | |
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \ | |
-H "Content-Type: application/json" \ | |
--data '{"title": "Requests"}' | |
The above HTTP request will create a namespace by the name Requests. The response should look something like this: | |
{ | |
"result": { | |
"id": "30b52f55aafb41d88546d01d5f69440a", |
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
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
async function handleRequest(request) { | |
return new Response("hello world") | |
} |
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 main | |
import ( | |
"encoding/binary" | |
"bytes" | |
"log" | |
"os/exec" | |
"github.com/xlab/pocketsphinx-go/sphinx" | |
pulse "github.com/mesilliac/pulse-simple" // pulse-simple |
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 executor | |
import ( | |
"log" | |
"sync/atomic" | |
) | |
// The Executor struct is the main executor for tasks. | |
// 'maxWorkers' represents the maximum number of simultaneous goroutines. | |
// 'ActiveWorkers' tells the number of active goroutines spawned by the Executor at given time. |
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
service HelloService { | |
rpc SayHello (HelloRequest) returns (HelloResponse); | |
} | |
message HelloRequest { | |
string greeting = 1; | |
} | |
message HelloResponse { | |
string reply = 1; |
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
message Person { | |
required string name = 1; | |
required int32 id = 2; | |
optional string email = 3; | |
enum PhoneType { | |
MOBILE = 0; | |
HOME = 1; | |
WORK = 2; | |
} |
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 function performs the given task concurrently by spawing a goroutine | |
// for each of those tasks. | |
func performAsyncTasks(task []Task) { | |
for _, task := range tasks { | |
// This will spawn a separate goroutine to carry out this task. | |
// This call is non-blocking | |
go task.Execute() | |
} | |
} |