go chapter 1
2024-09-04 17:15:03
case 1
// helloworld.go
package main import "fmt" func main() {
fmt.Println("Hello, 世界")
}
go run helloworld.go go build helloworldgo
./helloworld
case 2
package main import (
"fmt"
"os"
) func main() {
var s, sep string
for i := 1; i < len(os.Args); i++ {
s += sep + os.Args[i]
sep = " "
}
fmt.Println(s)
}
case 3 package main
import (
"fmt"
"os"
) func main() {
var s, sep string
for i, arg := range os.Args[1] {
fmt.Println(i, arg)
s += sep + arg
sep = " "
}
fmt.Println(s)
}
case 4 - http
package main import (
"fmt"
"net/http"
) func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello world")
} func main() {
http.HandleFunc("/", IndexHandler)
http.ListenAndServe("127.0.0.1:8000", nil)
}
case 5 - http prometheus
package main import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))
}
最新文章
- Swift enum(枚举)使用范例
- iOS 之项目中遇到的问题总结
- jQuery包装集
- 【转】8G内存下MySQL的优化详细方案
- lua定义一个简单的类
- 1.Dotnet Core安装
- 使用Linux碎解二
- SQL Server中 ldf 文件过大的解决方法
- Android应用崩溃后异常捕获并重启并写入日志
- re正则表达式16_managing complex regexes
- StackExchange.Redis.Extensions.Core 源码解读之 Configuration用法
- SynchronizationContext的研究之一(非WPF及Forms)
- linxu,window系统
- Android获取ip地址
- PowerDesigner从SqlServer 数据库中导入实体模型
- DatePicker的使用
- Java 中的函数式编程(Functional Programming):Lambda 初识
- KNN算法简单应用
- 测试工具之Fiddler
- [转]JAVA实现SFTP实例