如何互动go-rest-api& Docker上的go-ipf
就像这个
version: '3'
volumes:
peer.hyperism.com:
server.hyperism.com:
networks:
hyperism_net:
ipam:
config:
- subnet: ${PUBLIC_DATA_NETWORKS}
services:
# MongoDB
mongo_db:
container_name: "mongo_db_container"
image: mongo
ports:
- 27017:27017
volumes:
- ./mongodb:/data/db
restart: always
networks:
- hyperism_net
# Fiber
fiber:
env_file: .env
build: .
ports:
- 3000:3000
environment:
PORT: 3000
MONGO_URI: mongodb://mongo_db:27017
DB_NAME: my_db
depends_on:
- mongo_db
- ipfs0
restart: always
networks:
- hyperism_net
ipfs0:
container_name: ipfs0
image: ipfs/go-ipfs:latest
environment:
PORT: 5001
ports:
# - "4001:4001" # ipfs swarm - expose if needed/wanted
- 5001:5001 # ipfs api - expose if needed/wanted
- 8080:8080 # ipfs gateway - expose if needed/wanted
volumes:
- ./compose/ipfs0:/data/ipfs
networks:
- hyperism_net
一样
docker状态
docker- compose.yaml 使用Postman,IPF上没有添加任何内容,
./test.txt
{0xc000438660}
added
16:31:53 | 200 | 13ms | 127.0.0.1 | POST | /meta/upload
当我不在Docker上运行光纤,在go run main.go上, 没有返回 效果很好
./test.txt
{0xc000438660}
QmPBp8SZSCm6r6yuhsRYhpr2AqGmFihA8r7foHsuHpqdBF
added QmPBp8SZSCm6r6yuhsRYhpr2AqGmFihA8r7foHsuHpqdBF
16:31:56 | 200 | 13ms | 127.0.0.1 | POST | /meta/upload
该代码像此上传功能一样
func Upload(c *fiber.Ctx) error {
sh := shell.NewShell("localhost:5001")
file, err := c.FormFile("test")
// c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
fmt.Printf("./%s \n", file.Filename)
f, _ := file.Open()
cid, _ := sh.Add(bufio.NewReader(f))
fmt.Println(f)
fmt.Println(cid)
fmt.Printf("added %s\n", cid)
return err
}
,我猜
sh := shell.NewShell("localhost:5001")
应该修改行。
我应该怎么办?
docker-compose.yaml is like this
version: '3'
volumes:
peer.hyperism.com:
server.hyperism.com:
networks:
hyperism_net:
ipam:
config:
- subnet: ${PUBLIC_DATA_NETWORKS}
services:
# MongoDB
mongo_db:
container_name: "mongo_db_container"
image: mongo
ports:
- 27017:27017
volumes:
- ./mongodb:/data/db
restart: always
networks:
- hyperism_net
# Fiber
fiber:
env_file: .env
build: .
ports:
- 3000:3000
environment:
PORT: 3000
MONGO_URI: mongodb://mongo_db:27017
DB_NAME: my_db
depends_on:
- mongo_db
- ipfs0
restart: always
networks:
- hyperism_net
ipfs0:
container_name: ipfs0
image: ipfs/go-ipfs:latest
environment:
PORT: 5001
ports:
# - "4001:4001" # ipfs swarm - expose if needed/wanted
- 5001:5001 # ipfs api - expose if needed/wanted
- 8080:8080 # ipfs gateway - expose if needed/wanted
volumes:
- ./compose/ipfs0:/data/ipfs
networks:
- hyperism_net
docker status is like this
and when i post files with postman, nothing is added on the ipfs and nothing is returned
./test.txt
{0xc000438660}
added
16:31:53 | 200 | 13ms | 127.0.0.1 | POST | /meta/upload
when i run fiber not on docker, on local host with go run main.go,
the code works well like this
./test.txt
{0xc000438660}
QmPBp8SZSCm6r6yuhsRYhpr2AqGmFihA8r7foHsuHpqdBF
added QmPBp8SZSCm6r6yuhsRYhpr2AqGmFihA8r7foHsuHpqdBF
16:31:56 | 200 | 13ms | 127.0.0.1 | POST | /meta/upload
upload function is like this
func Upload(c *fiber.Ctx) error {
sh := shell.NewShell("localhost:5001")
file, err := c.FormFile("test")
// c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
fmt.Printf("./%s \n", file.Filename)
f, _ := file.Open()
cid, _ := sh.Add(bufio.NewReader(f))
fmt.Println(f)
fmt.Println(cid)
fmt.Printf("added %s\n", cid)
return err
}
i guess line
sh := shell.NewShell("localhost:5001")
should be modified.
what should i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论