Skip to content

Implementation of Go server.#1

Open
Chandanyadav2025 wants to merge 1 commit intolittle-bear-labs:mainfrom
Chandanyadav2025:goServer
Open

Implementation of Go server.#1
Chandanyadav2025 wants to merge 1 commit intolittle-bear-labs:mainfrom
Chandanyadav2025:goServer

Conversation

@Chandanyadav2025
Copy link

No description provided.

Comment on lines +19 to +24
myURL := "https://localhost:8090/?n=10"
parsedURL, err := url.Parse(myURL)
if err != nil {
fmt.Println("Can't parse URL", err)
return
}
Copy link
Contributor

@ckousik ckousik Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never fail. Also, this parses a constant string. You should be using the URL from the request. It should already be in a parsed state.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we make the value of n in url as variable value.
and how can we also parse more than two input value in raw query ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the request type: https://pkg.go.dev/net/http#Request
The incoming request is already parsed, so you can fetch a query value from there.

Secondly, the request Body can also contain data.

fmt.Println("Can't parse URL", err)
return
}
parts := strings.Split(parsedURL.RawQuery, "=")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a parsed query object. You shouldn't have to split here. https://pkg.go.dev/net/url#URL.Query

}

func main() {
http.HandleFunc("/", hello)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, you should really create an http.Server object.


func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8090", nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should look into the differences of binding to a port with just ":8090" vs "localhost:8090", "127.0.0.1:8090", your local network (192.168.x.x), and "0.0.0.0:8090". It is also trivial to make the port configurable here using an environment variable.

"strings"
)

func calculateSum(number int) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. Instead, create an endpoint which can accept an (id, SDP) pair (for now you can simulate SDP using any string), and return the SDP when it is queried.
eg.
Build two endpoints:

  1. POST / which accepts a JSON object which contains the id and an SDP string.
  2. GET /<id> which returns the SDP stored with id or 404 if not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants