直接使用 net.http 包,非常方便

// staticWeb
package main

import (
    "fmt"
    "net/http"
    "strconv"
)
//传入url参数、静态文件存放目录、监听的端口号
func StaticRunServer(urlPath string, filePath string, port int) {
    http.Handle(urlPath, http.FileServer(http.Dir(filePath)))
    fmt.Print("Run server!")
    portStr := strconv.Itoa(port)
    http.ListenAndServe(":"+portStr, nil)
}

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2021-07-09
  • 2022-02-12
  • 2022-12-23
  • 2021-10-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-02-01
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案