dongping9475 2016-03-09 11:24
浏览 85
已采纳

/ static /在此代码中是什么意思?

Im trying to serve static html file in GO. This is how my code in main() looks like.

http.Handle("/", http.FileServer(http.Dir("/static/")))
http.ListenAndServe(":8989", nil)

It works but i dont understand what does static mean! Someone please explain.

  • 写回答

2条回答 默认 最新

  • dongru3726 2016-03-09 11:46
    关注

    This means that whenever you handle requests that serves HTTP requests with the contents of the file system rooted at root, it try to server files declared in http.Dir which uses the operating system's file system implementation.

    This means that whenever you access your web server index url it will try to serve files under the operating system /static/ directory.

    To serve a directory on disk under an alternate URL path you can use StripPrefix to modify the request URL's path before the FileServer sees it.

    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("/your/directory/to/static/files"))))
    http.ListenAndServe(":8989", nil)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?