🚀
TypeScript 语法
使用熟悉的 TypeScript 语法编写代码,无需学习 Go 语法

import { Fprintf } from "fmt";
import { HandleFunc, ListenAndServe, Request, ResponseWriter } from "net/http";
function handler(w: ResponseWriter, r: Request): void {
const name = r.URL.Path.slice(1) || "World";
Fprintf(w, "Hello, %s!", name);
}
function main(): void {
HandleFunc("/", handler);
console.log("Server starting on http://localhost:8080");
ListenAndServe(":8080", null);
}package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[1:]
if name == "" {
name = "World"
}
fmt.Fprintf(w, "Hello, %s!", name)
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Server starting on http://localhost:8080")
http.ListenAndServe(":8080", nil)
}