zoukankan      html  css  js  c++  java
  • GO模仿python –m SimpleHTTPServer 8080

    Python 2.7版本内置此条命令:python –m SimpleHTTPServer 8080在终端输入此命令,一个HTTP服务器就起来了,8080端口是可选的,为空则默认为80端口,此操作会将当前所在的文件夹设置为默认的web目录。在我日常工作中,会经常用到此命令进行pc端与移动端文件的传输,但不知道什么原因会经常断线等,为此搜了下用go模仿此命令。项目地址:http://download.csdn.net/download/yhuangher/9985532

    package main
    import (
       "fmt"
       "net/http"
       "os"
       "os/exec"
       "strings"
    )
    
    func getCurrentPath()string{
       s,_ := exec.LookPath(os.Args[0])
       i := strings.LastIndex(s, "\")
       path := string(s[0 : i+1])
       return path
    }
    
    func main() {
       path:=getCurrentPath()
       fmt.Println("Current Path:"+path)
       http.Handle("/", http.FileServer(http.Dir("./")))
       err := http.ListenAndServe(":8080",nil)
       if err!=nil {
          fmt.Println(err)
          panic(err)
       }
    }
  • 相关阅读:
    Centos7.x做开机启动脚本
    贝叶斯方法之一
    R程序包
    c#调用R
    感悟--不可抗拒的行为
    IP等级
    词语
    关于editplus设置java和c#
    csc命令
    editplus配置csharp
  • 原文地址:https://www.cnblogs.com/Yellow0-0River/p/7543869.html
Copyright © 2011-2022 走看看