Skip to content

Commit

Permalink
setting up go server
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Sep 4, 2024
1 parent eec9790 commit 1171b3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions playground/go/arri.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ const goServer = defineServerConfig({
const watcher = chokidar.watch(["**/*.go"], { ignoreInitial: true });
let childProcess: ChildProcess | undefined;
function spawnProcess() {
childProcess = spawn("go", ["run", "."], {
execSync("go build -o .output/server", {
stdio: "inherit",
});
childProcess = spawn(".output/server", {
stdio: "inherit",
});
}
async function closeChildProcess() {
if (!childProcess) return true;
return new Promise((res, rej) => {
childProcess?.on("close", () => {
res(true);
});
childProcess?.on("exit", () => {
res(true);
});
childProcess?.on("close", () => res(true));
childProcess?.on("exit", () => res(true));
childProcess?.on("error", (err) => {
rej(err);
});
childProcess?.kill("SIGKILL");
childProcess?.kill("SIGTERM");
});
}
spawnProcess();
Expand Down
4 changes: 2 additions & 2 deletions playground/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type MyCustomContext struct{}

func onRequest(r *http.Request, c MyCustomContext) *arri.ErrorResponse {
fmt.Println("NEW REQUEST!!!!", r.URL.Path)
fmt.Println("NEW REQUEST", r.URL.Path)
return nil
}

Expand All @@ -25,7 +25,7 @@ func main() {
RpcRoutePrefix: "/procedures",
OnRequest: onRequest,
OnError: func(r *http.Request, mcc *MyCustomContext, err error) {
fmt.Println("NEW ERROR!!!", r.URL.Path, err.Error())
fmt.Println("NEW ERROR", r.URL.Path, err.Error())
},
}
app := arri.NewApp(
Expand Down

0 comments on commit 1171b3d

Please sign in to comment.