本文整理汇总了Golang中github.com/Scalingo/cli/debug.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decryptKey
func decryptKey(payload []byte, iv []byte, key []byte, newCypherFunc func([]byte) (cipher.Block, error)) ([]byte, error) {
decryptedPayload := make([]byte, len(payload))
block, err := newCypherFunc(key)
if err != nil {
return nil, errgo.Mask(err)
}
decrypter := cipher.NewCBCDecrypter(block, iv)
decrypter.CryptBlocks(decryptedPayload, payload)
debug.Println("End of private key payload:", decryptedPayload[len(decryptedPayload)-50:])
debug.Println("Length of payload:", len(decryptedPayload))
decryptedPayload = PKCS5Or7Unpadding(decryptedPayload)
debug.Println("Length of payload after trimming:", len(decryptedPayload))
return decryptedPayload, nil
}
示例2: exitCode
func (ctx *runContext) exitCode() (int, error) {
if ctx.attachURL == "" {
return -1, errgo.New("No attach URL to connect to")
}
req, err := http.NewRequest("GET", ctx.attachURL+"/wait", nil)
if err != nil {
return -1, errgo.Mask(err, errgo.Any)
}
req.SetBasicAuth("", config.AuthenticatedUser.AuthenticationToken)
res, err := http.DefaultClient.Do(req)
if err != nil {
return -1, errgo.Mask(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return -1, errgo.Notef(err, "fail to read body when getting exit code")
}
debug.Println("exit code body:", string(body))
waitRes := map[string]int{}
err = json.NewDecoder(bytes.NewBuffer(body)).Decode(&waitRes)
if err != nil {
return -1, errgo.Notef(err, "invalid response when getting exit code")
}
return waitRes["exit_code"], nil
}
示例3: loginWithSsh
func loginWithSsh(identity string) error {
debug.Println("Login through SSH, identity:", identity)
client, _, err := netssh.Connect(identity)
if err != nil {
return errgo.Notef(err, "fail to connect to SSH server")
}
channel, reqs, err := client.OpenChannel("session", []byte{})
if err != nil {
return errgo.Notef(err, "fail to open SSH channel")
}
defer client.Close()
_, err = channel.SendRequest("[email protected]", false, []byte{})
if err != nil {
return errgo.Notef(err, "SSH authentication request fails")
}
req := <-reqs
if req == nil {
return errgo.Newf("invalid response from auth request")
}
if req.Type != "[email protected]" {
return errgo.Newf("invalid response from SSH server, type is %v", req.Type)
}
payload := req.Payload
if len(payload) == 0 {
return errgo.Newf("invalid response from SSH server")
}
return loginWithApiKey(string(payload))
}
示例4: LoadAuth
func (a *CliAuthenticator) LoadAuth() (*scalingo.User, error) {
file, err := os.OpenFile(C.AuthFile, os.O_RDONLY, 0600)
if os.IsNotExist(err) {
return Auth()
}
if err != nil {
return nil, errgo.Mask(err, errgo.Any)
}
var authConfig auth.ConfigData
if err := json.NewDecoder(file).Decode(&authConfig); err != nil {
file.Close()
return nil, errgo.Mask(err, errgo.Any)
}
file.Close()
if authConfig.AuthDataVersion == "" {
debug.Println("auth config should be updated")
err = authConfig.MigrateToV1()
if err != nil {
return nil, errgo.Mask(err)
}
err = writeAuthFile(&authConfig)
if err != nil {
return nil, errgo.Mask(err)
}
debug.Println("auth config has been updated to V1")
}
var configPerHost auth.ConfigPerHostV1
err = json.Unmarshal(authConfig.AuthConfigPerHost, &configPerHost)
if err != nil {
return nil, errgo.Mask(err)
}
if user, ok := configPerHost[C.apiHost]; !ok {
return Auth()
} else {
if user == nil {
return Auth()
}
return user, nil
}
}
示例5: FlagAppAutoComplete
func FlagAppAutoComplete(c *cli.Context) bool {
apps, err := appsList()
if err != nil {
debug.Println("fail to get apps list:", err)
return false
}
for _, app := range apps {
fmt.Println(app.Name)
}
return true
}
示例6: appsList
func appsList() ([]*scalingo.App, error) {
var (
err error
apps []*scalingo.App
)
apps, err = appsAutoCompleteCache()
if err != nil {
debug.Println("fail to get applications autocomplete cache make GET request", err)
apps, err = scalingo.AppsList()
if err != nil || len(apps) == 0 {
return nil, errgo.Mask(err)
}
err = writeAppsAutoCompleteCache(apps)
if err != nil {
debug.Println("fail to write applications autocomplete cache", err)
}
}
return apps, nil
}
示例7: uploadFile
func (ctx *runContext) uploadFile(endpoint string, file string) error {
body := new(bytes.Buffer)
name := filepath.Base(file)
multipartFile := multipart.NewWriter(body)
writer, err := multipartFile.CreateFormFile("file", name)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
fd, err := os.OpenFile(file, os.O_RDONLY, 0600)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
_, err = stdio.Copy(writer, fd)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
err = fd.Close()
if err != nil {
return errgo.Mask(err, errgo.Any)
}
err = multipartFile.Close()
if err != nil {
return errgo.Mask(err, errgo.Any)
}
req, err := http.NewRequest("POST", endpoint, body)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
req.SetBasicAuth("", config.AuthenticatedUser.AuthenticationToken)
req.Header.Set("Content-Type", multipartFile.FormDataContentType())
fmt.Fprintln(ctx.waitingTextOutputWriter, "Upload", file, "to container.")
debug.Println("Endpoint:", req.URL)
res, err := httpclient.Do(req)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
defer res.Body.Close()
if res.StatusCode != 200 {
b, _ := ioutil.ReadAll(res.Body)
return errgo.Newf("Invalid return code %v (%s)", res.Status, strings.TrimSpace(string(b)))
}
return nil
}
示例8: ParseJSON
func ParseJSON(res *http.Response, data interface{}) error {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return errgo.Newf("fail to read body of request %v, %v", res.Request, err)
}
debug.Println(string(body))
err = json.Unmarshal(body, data)
if err != nil {
return errgo.Newf("fail to parse JSON of request %v, %v", res.Request, err)
}
return nil
}
示例9: scalingoRemotes
func scalingoRemotes(directory string) (gitremote.Remotes, error) {
matchedRemotes := make(gitremote.Remotes, 0)
remotes, err := gitremote.List(directory)
if err != nil {
return nil, err
}
for _, remote := range remotes {
matched, err := regexp.Match(".*scalingo.com:.*.git", []byte(remote.URL))
if err == nil && matched {
debug.Println("[AppDetect] GIT remote found:", remote)
matchedRemotes = append(matchedRemotes, remote)
}
}
return matchedRemotes, nil
}
示例10: HandleSignal
func HandleSignal(s os.Signal, socket net.Conn, runUrl string) {
switch s {
case syscall.SIGINT:
socket.Write([]byte{0x03})
case syscall.SIGQUIT:
socket.Write([]byte{0x1c})
case syscall.SIGTSTP:
socket.Write([]byte{0x1a})
case syscall.SIGWINCH:
err := updateTtySize(runUrl)
if err != nil {
debug.Println("WARN: Error when updating terminal size:", err)
}
}
}
示例11: streamLogs
func streamLogs(logsRawURL string, filter string) error {
var (
err error
buffer [20480]byte
event WSEvent
)
logsURL, err := url.Parse(logsRawURL)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
if logsURL.Scheme == "https" {
logsURL.Scheme = "wss"
} else {
logsURL.Scheme = "ws"
}
logsURLString := fmt.Sprintf("%s&stream=true", logsURL.String())
if filter != "" {
logsURLString = fmt.Sprintf("%s&filter=%s", logsURLString, filter)
}
conn, err := websocket.Dial(logsURLString, "", "http://scalingo-cli.local/"+config.Version)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
for {
n, err := conn.Read(buffer[:])
if err != nil {
return errgo.Mask(err, errgo.Any)
}
debug.Println(string(buffer[:n]))
err = json.Unmarshal(buffer[:n], &event)
if err != nil {
return errgo.Notef(err, "invalid JSON %v", string(buffer[:n]))
}
switch event.Type {
case "ping":
case "log":
fmt.Println(strings.TrimSpace(event.Log))
}
}
}
示例12: ScalingoRepo
func ScalingoRepo(directory string, remoteName string) (string, error) {
remotes, err := gitremote.List(directory)
if err != nil {
return "", err
}
for i := 0; i < 2; i++ {
for _, remote := range remotes {
if remote.Name == remoteName {
matched, err := regexp.Match(".*scalingo.com:.*.git", []byte(remote.URL))
if err == nil && matched {
debug.Println("[AppDetect] GIT remote found:", remote)
return filepath.Base(strings.TrimSuffix(remote.Repository(), ".git")), nil
}
}
}
remoteName = "scalingo-" + remoteName
}
return "", errgo.Newf("Scalingo GIT remote hasn't been found")
}
示例13: CurrentApp
func CurrentApp(c *cli.Context) string {
var repoName string
if c.GlobalString("app") != "<name>" {
repoName = c.GlobalString("app")
} else if c.String("app") != "<name>" {
repoName = c.String("app")
} else if os.Getenv("SCALINGO_APP") != "" {
repoName = os.Getenv("SCALINGO_APP")
} else if dir, ok := DetectGit(); ok {
repoName, _ = ScalingoRepo(dir, c.GlobalString("remote"))
}
if repoName == "" {
fmt.Println("Unable to find the application name, please use --app flag.")
os.Exit(1)
}
debug.Println("[AppDetect] App name is", repoName)
return repoName
}
示例14: ScalingoRepoComplete
func ScalingoRepoComplete(dir string) []string {
var repos []string
remotes, err := scalingoRemotes(dir)
if err != nil {
debug.Println("[AppDetectCompletion] fail to get scalingo remotes in", dir)
return repos
}
for _, remote := range remotes {
if strings.HasPrefix(remote.Name, "scalingo-") {
repos = append(repos, remote.Name[9:])
} else {
repos = append(repos, remote.Name)
}
}
return repos
}
示例15: NewRequestFailedError
func NewRequestFailedError(res *http.Response, req *APIRequest) error {
debug.Println("APIRequest Error:", res.StatusCode, req.Method, req.Endpoint)
defer res.Body.Close()
switch res.StatusCode {
case 400:
var badRequestError BadRequestError
err := ParseJSON(res, &badRequestError)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
return &RequestFailedError{res.StatusCode, badRequestError, req}
case 401:
return &RequestFailedError{res.StatusCode, errgo.New("unauthorized - you are not authorized to do this operation"), req}
case 402:
var paymentRequiredErr PaymentRequiredError
err := ParseJSON(res, &paymentRequiredErr)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
return &RequestFailedError{res.StatusCode, paymentRequiredErr, req}
case 404:
var notFoundErr NotFoundError
err := ParseJSON(res, ¬FoundErr)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
return &RequestFailedError{res.StatusCode, notFoundErr, req}
case 422:
var unprocessableError UnprocessableEntity
err := ParseJSON(res, &unprocessableError)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
return &RequestFailedError{res.StatusCode, unprocessableError, req}
case 500:
return &RequestFailedError{res.StatusCode, errgo.New("server internal error - our team has been notified"), req}
default:
return &RequestFailedError{res.StatusCode, fmt.Errorf("invalid status from server: %v", res.Status), req}
}
}