Cant use a GoLang http server in vs code

William Roberts 0 Reputation points

When i try to run my http server (written in go) in vs code, it comes up with the error: main.go:1:1: expected 'package', found 'EOF'. but it works when i write it in note pad and do it manually(not in vs code)(it dosent work even if it was created in vs code and i compiled and run outside of vs code)

Heres the code:

package main

import "net/http"

func main() {

    http.ListenAndServe(":8080", nil)


and i believe i have the go.mod file

heres what is in it

module http-server

go 1.22.0

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
938 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,106 Reputation points Microsoft Vendor

    Hello @William Roberts,

    Thank you for taking time to post this issue in the Microsoft Q&A forum.

    VS Code(is different from VS) is currently not supported in the Microsoft Q&A forums, the supported products are listed over here:

    For the related questions about VS Code, please kindly post here: Github – vscode.

    Thanks for your understanding, have a great day.

    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments