63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"golang.org/x/tools/present"
|
|
)
|
|
|
|
const (
|
|
fullParse = present.ParseMode(0)
|
|
path = "code.osinet.fr/fgm/go__course/master/present/slides/generics-en.slide"
|
|
name = "Generics intro"
|
|
)
|
|
|
|
func findPresentation(relpath string) (io.ReadCloser, error) {
|
|
gopath, ok := os.LookupEnv("GOPATH")
|
|
if !ok {
|
|
return nil, errors.New("GOPATH not found in environment")
|
|
}
|
|
gopaths := strings.Split(gopath, ":")
|
|
if len(gopaths) < 1 {
|
|
return nil, errors.New("No segment found in GOPATH")
|
|
}
|
|
for i, workspace := range gopaths {
|
|
log.Printf("Looking in segment %d: %s\n", i, workspace)
|
|
path := filepath.Join(workspace, "src", relpath)
|
|
if _, err := os.Stat(path); err != nil {
|
|
continue
|
|
}
|
|
dir, file := filepath.Split(path)
|
|
if err := os.Chdir(dir); err != nil {
|
|
return nil, fmt.Errorf("Failed chdir(%s): %w", dir, err)
|
|
}
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Opening %s: %w\n", path, err)
|
|
}
|
|
log.Printf("Opened %s OK", path)
|
|
return f, nil
|
|
}
|
|
return nil, os.ErrNotExist
|
|
}
|
|
|
|
func main() {
|
|
rc, err := findPresentation(path)
|
|
if err != nil {
|
|
log.Fatalf("Failed finding presentation file %s: %v\n", path, err)
|
|
}
|
|
defer rc.Close()
|
|
|
|
d, err := present.Parse(rc, name, fullParse)
|
|
if err != nil {
|
|
log.Fatalf("Parsing %s: %v\n", path, err)
|
|
}
|
|
spew.Dump(d)
|
|
}
|