douweng3383 2018-04-12 19:56
浏览 67
已采纳

Golang Gorilla Mux服务器本地软件包导入和未使用问题

I'm testing a simple server app with Gorilla Mux. I keep getting undefined error when running the app. This is the structure of the app

src/ptest/
├── app
│   └── app.go
└── main.go

main.go

package main

import (
    "fmt"
    "ptest/app"
)

func main() {
    fmt.Println("Hello Testing App")
    app := App{}
}

app.go

package app

import (
    "fmt"
    "log"
    "net/http"
    "github.com/gorilla/mux"
)

type App struct {
    Router *mux.Router
}

func (A *App) Run() {
    fmt.Println("Listening at :8080")
    log.Fatal(http.ListenAndServe(":8080", A.Router))
}

As you can see, I have a main that initialized app by importing from ptest/app. But I am getting an error when I go run *go:

# command-line-arguments
./main.go:5:2: imported and not used: "ptest/app"
./main.go:10:9: undefined: App

This is my go env. I am wondering if something not right with my environment?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/haha/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/haha/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 python跨服务器实现复制 ,剪切的功能需求
      • ¥15 android sqlite数据库如何读取显示数据(语言-java)
      • ¥15 R语言,单因素cox检验,时间分层后,使用coz.zph()函数再次ph假设检验时报错,如何解决?
      • ¥15 关于#C语言冒泡排序型#的问题,如何解决?
      • ¥15 如何预处理存在负值的样本数据,使其能够全都成为正的
      • ¥15 SW画图拖影,平滑处理如何关闭
      • ¥15 请问怎么通过css改变图片颜色
      • ¥15 Blender: auto rig pro骨骼动画导出后变形穿模
      • ¥15 C51单片机的设计思路哈
      • ¥15 Linux脏牛提权漏洞