简体   繁体   English

如何在终端重新加载 Go 光纤?

[英]How to reload Go Fiber in the terminal?

I am completely new to this community but would really appreciate if someone can help me with this problem I am facing.我对这个社区完全陌生,但如果有人能帮助我解决我面临的这个问题,我将不胜感激。 I am currently following the basic tutorial of the simple Hello World app but how can we update the code to say something else and that to be updated in our output on the browser in real time?我目前正在学习简单的 Hello World 应用程序的基本教程,但我们如何更新代码以说明其他内容,并在浏览器上实时更新我们的 output?


package main

import (
    "log"

    "github.com/gofiber/fiber/v2"
)

func main() {
    // Fiber instance
    app := fiber.New()

    // Routes
    app.Get("/", hello)

    // Start server
    log.Fatal(app.Listen(":3000"))
}

// Handler
func hello(c *fiber.Ctx) error {
    return c.SendString("Hello, World 👋!")
}

You're talking about hot-reloading (live-reloading).您在谈论热重载(实时重载)。 Go itself do not have it implemented by default to achieve that, but you can do it with the package called air https://github.com/cosmtrek/air . Go 本身并没有默认实现它,但您可以使用名为air https://github.com/cosmtrek/air的 package 来实现。 Here is a great tutorial how to use it with Fiber: https://dev.to/komfysach/go-live-reload-using-air-40ll这是一个很好的教程,如何将它与 Fiber 一起使用: https://dev.to/komfysach/go-live-reload-using-air-40ll

you can use nodemon你可以使用nodemon

install nodemon ' nodejs required'安装nodemon '需要nodejs '

npm install -g nodemon

and use the command to enable hot-reolading并使用命令启用热重载

nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run main.go

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM