File: example_test.go

package info (click to toggle)
golang-gopkg-sourcemap.v1 1.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 128 kB
  • sloc: makefile: 6
file content (37 lines) | stat: -rw-r--r-- 673 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package sourcemap_test

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"gopkg.in/sourcemap.v1"
)

func ExampleParse() {
	mapURL := "file:///usr/share/javascript/jquery/jquery.min.map"

	trans := &http.Transport{}
	trans.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))

	cli := &http.Client{Transport: trans}
	resp, err := cli.Get(mapURL)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	smap, err := sourcemap.Parse(mapURL, b)
	if err != nil {
		panic(err)
	}

	line, column := 5, 6789
	file, fn, line, col, ok := smap.Source(line, column)
	fmt.Println(file, fn, line, col, ok)
}