beego热更新

package main

import (
	"log"
	"net/http"
	"os"
	"strconv"

	"github.com/astaxie/beego/grace"
)

func handler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("WORLD!"))
	w.Write([]byte("ospid:" + strconv.Itoa(os.Getpid())))
}

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/hello", handler)

	err := grace.ListenAndServe("localhost:8080", mux)
	if err != nil {
		log.Println(err)
	}
	log.Println("Server on 8080 stopped")
	os.Exit(0)
}

打开两个终端

一个终端输入:ps -ef|grep 应用名

一个终端输入请求:curl “http://127.0.0.1:8080/”

热升级

kill -HUP 进程ID

打开一个终端输入请求:curl “http://127.0.0.1:8080/?sleep=0”

你可能感兴趣的:(golang)