github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/cmd/tip/talks.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"errors"
    10  	"fmt"
    11  	"os"
    12  	"os/exec"
    13  	"path/filepath"
    14  	"runtime"
    15  )
    16  
    17  type talksBuilder struct {
    18  }
    19  
    20  func (b talksBuilder) Signature(heads map[string]string) string {
    21  	return heads["talks"]
    22  }
    23  
    24  const talksToolsRev = "ac6d9c1d842f9b6482f39f7a172e0251a0f7cbc0"
    25  
    26  func (b talksBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
    27  	toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
    28  	if err := checkout(repoURL+"tools", talksToolsRev, toolsDir); err != nil {
    29  		return nil, err
    30  	}
    31  	talksDir := filepath.Join(dir, "gopath/src/golang.org/x/talks")
    32  	if err := checkout(repoURL+"talks", heads["talks"], talksDir); err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	goDir := os.Getenv("GOROOT_BOOTSTRAP")
    37  	if goDir == "" {
    38  		goDir = runtime.GOROOT()
    39  	}
    40  	goBin := filepath.Join(goDir, "bin/go")
    41  	goPath := filepath.Join(dir, "gopath")
    42  	presentPath := "golang.org/x/tools/cmd/present"
    43  	install := exec.Command(goBin, "install", "-tags=appenginevm", presentPath)
    44  	install.Env = []string{"GOROOT=" + goDir, "GOPATH=" + goPath}
    45  	if err := runErr(install); err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	talksBin := filepath.Join(goPath, "bin/present")
    50  	presentSrc := filepath.Join(goPath, "src", presentPath)
    51  	present := exec.Command(talksBin, "-http="+hostport, "-base="+presentSrc)
    52  	present.Dir = talksDir
    53  	// TODO(adg): log this somewhere useful
    54  	present.Stdout = os.Stdout
    55  	present.Stderr = os.Stderr
    56  	if err := present.Start(); err != nil {
    57  		return nil, err
    58  	}
    59  	return present, nil
    60  }
    61  
    62  var talksMsg = []byte("Talks - The Go Programming Language")
    63  
    64  func (b talksBuilder) HealthCheck(hostport string) error {
    65  	body, err := getOK(fmt.Sprintf("http://%v/", hostport))
    66  	if err != nil {
    67  		return err
    68  	}
    69  	if !bytes.Contains(body, talksMsg) {
    70  		return errors.New("couldn't match string")
    71  	}
    72  	return nil
    73  }