|
|
本帖最后由 zhongziso 于 2021-11-10 20:19 编辑
感谢大佬@Xhofe 指点
我们都知道油管的api有额度限制。这个go语言版的是没有限制的。
访问http://127.0.0.1:8080?keyword=用户输入的关键词
就可以输出json了
效果如图

- package main
- import (
- "encoding/json"
- "fmt"
- "log"
- "net/http"
- "github.com/raitonoberu/ytsearch"
- )
- func main() {
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- a := r.URL.Query().Get("keyword")
- search := ytsearch.Search(a)
- result, err := search.Next()
- if err != nil {
- panic(err)
- }
- jsonstr, _ := json.Marshal(result)
- fmt.Fprintf(w, "%v", string(jsonstr))
- })
- log.Fatal(http.ListenAndServe(":8080", nil))
- }
复制代码 |
|