duanchao1002 2018-05-02 13:48
浏览 42
已采纳

转到代码不起作用

I am trying out following sample snippet to run on my vscode editor

below is a snippen which i think is problematic. Vscode does point to some error but maybe I am missing that.

app.go

package main

import {
    "database/sql"
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "github.com/gorilla/mux"
    _ "github.com/lib/pq"
}

type App struct {
    Router *mux.Router
    DB *sql.DB
}
//init and other functions here

model.go

package main

type product struct {
   ID    int     `json:"id"`
   Name  string  `json:"name"`
   Price float64 `json:"price"`
}
//some code below

When I try to run vscode debugger with above given settings, it gives me below errors:

can't load package: package .: 
app.go:3:8: expected 'STRING', found '{'
app.go:4:2: expected ';', found 'STRING' "database/sql"
exit status 1
Process exiting with code: 1

I am not able to debug as this is very vague to me and I have tried looking for it on other forums. Would be greatful if someone can help with what to do with the above error.

  • 写回答

1条回答 默认 最新

  • dougong5285 2018-05-02 13:50
    关注

    The import block is supposed to be surrounded in parentheses, not braces.

    import (
        "database/sql"
        "encoding/json"
        "fmt"
        "log"
        "net/http"
        "github.com/gorilla/mux"
        _ "github.com/lib/pq"
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同