ccaa_web.go 406 B

123456789101112131415161718192021222324
  1. //Golang实现一个简单的WebServer
  2. package main
  3. import (
  4. "os"
  5. "net/http"
  6. //"fmt"
  7. )
  8. func main() {
  9. //声明2个变量
  10. var dir,port string
  11. //判断参数的长度
  12. if len(os.Args) == 3 {
  13. dir = os.Args[1]
  14. port = os.Args[2]
  15. } else{
  16. //如果没有参数,则使用默认
  17. dir = "/etc/ccaa/AriaNg"
  18. port = "6080"
  19. }
  20. panic(http.ListenAndServe(":" + port, http.FileServer(http.Dir(dir))))
  21. }