Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
baletu committed Mar 28, 2024
1 parent 1da872d commit 23b2809
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@ package main

import (
"flag"
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"os"
"path/filepath"
)

func main() {
router := httprouter.New()
//获取当前目录

var host string

//解析命令行参数
flag.StringVar(&host, "host", "127.0.0.1:1234", "监听地址")
flag.Parse()

dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}

//获取当前路径
dir, _ := os.Getwd()
//设置静态文件目录
router.ServeFiles("/*filepath", http.Dir(dir))
fmt.Println(fmt.Sprintf("当前所在目录:%s", dir))

log.Printf("server start at http://%s", host)
err = http.ListenAndServe(host, router)
err := http.ListenAndServe(host, router)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 23b2809

Please sign in to comment.