Cant use a GoLang http server in vs code

William Roberts 0 Reputation points
2024-03-17T00:45:06.4533333+00:00

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
    2024-03-18T10:03:17.56+00:00

    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: https://docs.microsoft.com/en-us/answers/products/

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

    Thanks for your understanding, have a great day.

    Best Regards,

    Tianyu


    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