go-oembed

Golang package for parsing Oembed data from known providers by URL

  • 所有者: dyatlov/go-oembed
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

GO Oembed

GoDoc

Go Oembed provides methods to retrieve oEmbed data from known providers.
The provider list can be fetched from this repository or from oembed.com/providers.json

Install

go get github.com/dyatlov/go-oembed/oembed

Example

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"strings"

	"github.com/dyatlov/go-oembed/oembed"
)

func main() {
	data, err := ioutil.ReadFile("../providers.json")

	if err != nil {
		panic(err)
	}

	oe := oembed.NewOembed()
	oe.ParseProviders(bytes.NewReader(data))

	for {

		reader := bufio.NewReader(os.Stdin)
		fmt.Print("Enter url: ")
		url, _ := reader.ReadString('\n')

		url = strings.Trim(url, "\r\n")

		if url == "" {
			break
		}

		item := oe.FindItem(url)

		if item != nil {
			info, err := item.FetchOembed(oembed.Options{URL: url})
			if err != nil {
				fmt.Printf("An error occured: %s\n", err.Error())
			} else {
				if info.Status >= 300 {
					fmt.Printf("Response status code is: %d\n", info.Status)
				} else {
					fmt.Printf("Oembed info:\n%s\n", info)
				}
			}
		} else {
			fmt.Println("nothing found :(")
		}

	}
}

主要指标

概览
名称与所有者dyatlov/go-oembed
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-09-09 14:50:33
推送于2023-01-23 11:14:54
最后一次提交2019-11-03 16:05:36
发布数0
用户参与
星数20
关注者数3
派生数12
提交数26
已启用问题?
问题数2
打开的问题数0
拉请求数3
打开的拉请求数2
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?