V
V
Vipka1n2022-03-31 05:53:45
go
Vipka1n, 2022-03-31 05:53:45

Package command-line-arguments is not a main package Golang Error?

package mine

import (
  "fmt"
  "html/template"
  "net/http"
)

func index(w http.ResponseWriter, r *http.Request) {
  t, err := template.ParseFiles("templates/index.html", "templates/footer.html", "templates/header.html")

  if err != nil {
    fmt.Fprint(w, err.Error())
  }
}
func handleFunc() {
  http.HandleFunc("/", index)
  http.ListenAndServe("4000", nil)
}

func main() {
  handleFunc()
}


VSS claims that the error is here

func index(w http.ResponseWriter, r *http.Request) {
  t, err := template.ParseFiles("templates/index.html", "templates/footer.html", "templates/header.html")

  if err != nil {
    fmt.Fprint(w, err.Error())
  }
}


But in the lesson the code is identical, the compilation goes well.
In my case, an error pops up

package command-line-arguments is not a main package

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2022-03-31
@Maksclub

You have an error only in the wrong package name (you need main) and in the unused variable t
so the code works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question