在项目中导入pb.go文件

在项目中导入pb.go文件,go,protocol-buffers,Go,Protocol Buffers,如何导入生成的pb.go文件,以便调用其中的方法?我访问了go的所有示例,它们似乎都是通过github.com/… 示例。开始 import ( "github.com/go-chi/chi" chiMiddleware "github.com/go-chi/chi/middleware" "google.golang.org/grpc" "net/http" "github.com/easyCZ/grpc-web-hacker-news/server/h

如何导入生成的
pb.go
文件,以便调用其中的方法?我访问了go的所有示例,它们似乎都是通过
github.com/…

示例。开始

import (
    "github.com/go-chi/chi"
    chiMiddleware "github.com/go-chi/chi/middleware"
    "google.golang.org/grpc"
    "net/http"
    "github.com/easyCZ/grpc-web-hacker-news/server/hackernews"
    hackernews_pb "github.com/easyCZ/grpc-web-hacker-news/server/proto" // Proto directory.
    "google.golang.org/grpc/grpclog"
    "github.com/improbable-eng/grpc-web/go/grpcweb"
    "github.com/go-chi/cors"
    "github.com/easyCZ/grpc-web-hacker-news/server/proxy"
    "github.com/easyCZ/grpc-web-hacker-news/server/middleware"
)

func main() {
    grpcServer := grpc.NewServer()
    hackernewsService := hackernews.NewHackerNewsService(nil)
    hackernews_pb.RegisterHackerNewsServiceServer(grpcServer, hackernewsService)
    ...

目录结构

One could do a 
go mod init project
and subsequently import go files that reside in some folder, e.g. folder as:

import "project/folder"

可以执行一个
go mod init项目
,然后导入驻留在某个文件夹中的go文件,例如文件夹:


我创建了几个包含此结构的文件,例如n3dr、bcbsn、go yq、go multipart和dip。

“它们似乎都是使用github.com/…”这不是巧合:您不能在go中导入文件,只能导入包。请阅读,特别是关于和的部分。