Answer the question
In order to leave comments, you need to log in
Golang not running main()?
I am writing a small server to get addresses of microservices.
The server consists of several directories that are imported, as well as the main files main.go and server.go
main.go:
package main
import (
"fmt"
)
const (
port = ":7777"
)
func main() {
fmt.Println("Starting Servers")
serve()
}
package main
import (
"./data_storage"
pb "./proto"
"./platform"
"./user"
"fmt"
"google.golang.org/grpc"
"log"
"net"
)
func serve() {
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
// ----- User -----
fmt.Println("\nRegistering User Address Server")
pb.RegisterUserStackServer(s, &user.Server{})
// ----- Platform -----
fmt.Println("\nRegistering Platform Address Server")
pb.RegisterPlatformStackServer(s, &platform.Server{})
// ----- DataStorage -----
fmt.Println("\nRegistering DataStorage Address Server")
pb.RegisterDataStorageStackServer(s, &data_storage.Server{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
Answer the question
In order to leave comments, you need to log in
go run
compiles and runs the program https://golang.org/cmd/go/#hdr-Compile_and_run_Go_...go build
only compiles https://golang.org/cmd/go/#hdr-Compile_and_run_Go_... The compiled program can then be run as regular executable
When you run go run main.go
or go build main.go
, you get what you want. In the first case, there will be compilation and launch, in the second, only compilation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question