translation

live playlist (滑动窗口)构造

原文 概述 示例 EXTM3U EXT-X-PLAYLIST-TYPE EXT-X-TARGETDURATION EXT-X-VERSION EXT-X-MEDIA-SEQUENCE EXTINF 更新 playlist 文件 概述 在直播会话中,当生成新的媒体文件且可访问时,通过从文件中移除媒体 URL 来更新索引文件。EXT-X-ENDL

Loops and Functions

```go /* Exercise: Loops and Functions As a way to play with functions and loops, let’s implement a square root function: given a number x, we want to find the number z for which z² is most nearly x. Computers typically compute the square root of x using a loop. Starting with some guess z, we can adjust z based on how close z² is to x, producing a better guess:

Maps

```go /* Exercise: Maps Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful. */ package main import ( “strings” "golang.org/x/tour/wc" ) func wordCount(s string) map[string]int { m := make(map[string]int) var ss []string ss = strings.Fields(s) for i := 0; i < len(ss); i++ { m[ss[i]]++ }

quick 包

概述 索引 参考 Golang 官网文档 学习。 导入语句:import "testing/quick" 概述 quick 包实现了帮辅助黑盒测试的工具函数。 testing/quick 包被冻结,且不再接受新特性。 索引 参考

Readers

```go /* Exercise: Readers Implement a Reader type that emits an infinite stream of the ASCII character ‘A’. */ package main import “golang.org/x/tour/reader” type myReader struct{} func (r myReader) Read(c []byte) (int, error) { i := 0 for ; i < len©; i++ { c[i] = ‘A’ } for ; i < cap©; i++ { c = append(c, ‘A’) } return cap(c), nil } func main() { reader.Validate(myReader{}) }

rot13Reader

```go /* Exercise: rot13Reader A common pattern is an io.Reader that wraps another io.Reader, modifying the stream in some way. For example, the gzip.NewReader function takes an io.Reader (a stream of compressed data) and returns a *gzip.Reader that also implements io.Reader (a stream of the decompressed data). Implement a rot13Reader that implements io.Reader and reads from an io.Reader, modifying the stream by applying the rot13 substitution cipher to all alphabetical characters.

Slices

/* Exercise: Slices Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values. The choice of image is up to you. Interesting functions include (x+y)/2, x*y, and x^y. (You need to use a loop to allocate each []uint8 inside the [][]uint8.

Stringers

/* Exercise: Stringers Make the IPAddr type implement fmt.Stringer to print the address as a dotted quad. For instance, IPAddr{1, 2, 3, 4} should print as "1.2.3.4". */ package main import ( "fmt" "strconv" "strings" ) type iPAddr [4]byte func (ip iPAddr) String() string { arr := []string{"0", ".", "0", ".", "0", ".", "0"} for i := 0; i < 4; i++ { arr[i<<1] = strconv.Itoa(int(ip[i])) } sip := strings.Join(arr, "") return sip } func main() { hosts := map[string]iPAddr{ "loopback": {127, 0, 0, 1}, "googleDNS": {8, 8, 8, 8}, } for name, ip := range hosts { fmt.

testing 包

概述 基准测试 示例函数 跳过测试 子测试项目和子基准测试 Main 索引 例子 子目录 参考 Golang 官网文档 学习。 导入语句:import "testing" 概述 testing 包提供对 Go 包的自动测试。

VOD playlist 构造

原文 概述 示例 EXTM3U EXT-X-TARGETDURATION EXT-X-VERSION EXT-X-MEDIA-SEQUENCE EXTINF EXT-X-ENDLIST 相对路径 概述 对于 VOD(video on demand, 点播) 会话,可以访问的媒体文件表示显示的整个时间段。索引文件是静态的,且包含相关 URL 的一个完整列