forked from little-bear-labs/quic-over-ice-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (35 loc) · 706 Bytes
/
main.go
File metadata and controls
38 lines (35 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
)
func calculateSum(number int) int {
sum := 0
for i := 1; i <= number; i++ {
sum += i
}
return sum
}
func hello(w http.ResponseWriter, req *http.Request) {
myURL := "https://localhost:8090/?n=10"
parsedURL, err := url.Parse(myURL)
if err != nil {
fmt.Println("Can't parse URL", err)
return
}
parts := strings.Split(parsedURL.RawQuery, "=")
n, err := strconv.Atoi(parts[1])
if err != nil {
fmt.Println("number is not found", err)
return
}
var res int = calculateSum(n)
fmt.Fprintf(w, "The sum from 1 to %d is: %d", n, res)
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8090", nil)
}