@@ -38,9 +38,10 @@
|
||||
"clean:modules": "rm -rf node_modules"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/platform-browser": "^0.74.0"
|
||||
"@effect/platform-node": "^0.104.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@effect/platform": "^0.94.2",
|
||||
"effect": "^3.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import net from "node:net"
|
||||
import { HttpClient } from "@effect/platform"
|
||||
import { NodeHttpClient, NodeRuntime } from "@effect/platform-node"
|
||||
import { Effect, Layer } from "effect"
|
||||
|
||||
|
||||
const DockerSocketAgent = Effect.acquireRelease(
|
||||
Effect.sync(() => net.createConnection({ path: "/var/run/docker.sock" })),
|
||||
socket => Effect.sync(() => socket.end()),
|
||||
).pipe(
|
||||
Effect.andThen(socket => NodeHttpClient.makeAgentLayer({ socket })),
|
||||
Layer.unwrapScoped,
|
||||
)
|
||||
|
||||
const DockerHttpClient = Layer.provide(NodeHttpClient.layerWithoutAgent, DockerSocketAgent)
|
||||
|
||||
Effect.gen(function*() {
|
||||
const client = yield* HttpClient.HttpClient
|
||||
const response = yield* client.get("http://localhost/containers/json")
|
||||
|
||||
console.log(yield* response.json)
|
||||
}).pipe(
|
||||
Effect.provide(DockerHttpClient),
|
||||
NodeRuntime.runMain,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user