本文整理汇总了Golang中github.com/apex/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: logsCmdRun
func logsCmdRun(c *cobra.Command, args []string) {
lv := &logsCmdLocalValues
l, err := pv.project.Logs(pv.session, lv.name, lv.Filter)
if err != nil {
log.Fatalf("error: %s", err)
}
if lv.Follow {
for event := range l.Tail() {
fmt.Printf("%s", *event.Message)
}
if err := l.Err(); err != nil {
log.Fatalf("error: %s", err)
}
}
events, err := l.Fetch()
if err != nil {
log.Fatalf("error: %s", err)
}
for _, event := range events {
fmt.Printf("%s", *event.Message)
}
}
示例2: preRun
func (pv *PersistentValues) preRun(c *cobra.Command, args []string) {
if l, err := log.ParseLevel(pv.LogLevel); err == nil {
log.SetLevel(l)
}
pv.session = session.New(aws.NewConfig())
pv.project = &project.Project{
Log: log.Log,
Path: ".",
}
if pv.DryRun {
log.SetLevel(log.WarnLevel)
pv.project.Service = dryrun.New(pv.session)
pv.project.Concurrency = 1
} else {
pv.project.Service = lambda.New(pv.session)
}
if pv.Chdir != "" {
if err := os.Chdir(pv.Chdir); err != nil {
log.Fatalf("error: %s", err)
}
}
if err := pv.project.Open(); err != nil {
log.Fatalf("error opening project: %s", err)
}
}
示例3: Action
// Action is the default cli action to execute
func Action(c *cli.Context) {
// Initialize the SSH server
server, err := ssh2docker.NewServer()
if err != nil {
log.Fatalf("Cannot create server: %v", err)
}
// Restrict list of allowed images
if c.String("allowed-images") != "" {
server.AllowedImages = strings.Split(c.String("allowed-images"), ",")
}
// Configure server
server.DefaultShell = c.String("shell")
server.DockerRunArgsInline = c.String("docker-run-args")
server.DockerExecArgsInline = c.String("docker-exec-args")
server.NoJoin = c.Bool("no-join")
server.CleanOnStartup = c.Bool("clean-on-startup")
server.PasswordAuthScript = c.String("password-auth-script")
server.PublicKeyAuthScript = c.String("publickey-auth-script")
server.LocalUser = c.String("local-user")
server.Banner = c.String("banner")
// Register the SSH host key
hostKey := c.String("host-key")
switch hostKey {
case "built-in":
hostKey = DefaultHostKey
case "system":
hostKey = "/etc/ssh/ssh_host_rsa_key"
}
err = server.AddHostKey(hostKey)
if err != nil {
log.Fatalf("Cannot add host key: %v", err)
}
// Bind TCP socket
bindAddress := c.String("bind")
listener, err := net.Listen("tcp", bindAddress)
if err != nil {
log.Fatalf("Failed to start listener on %q: %v", bindAddress, err)
}
log.Infof("Listening on %q", bindAddress)
// Initialize server
if err = server.Init(); err != nil {
log.Fatalf("Failed to initialize the server: %v", err)
}
// Accept new clients
for {
conn, err := listener.Accept()
if err != nil {
log.Errorf("Accept failed: %v", err)
continue
}
go server.Handle(conn)
}
}
示例4: main
func main() {
args, err := docopt.Parse(usage, nil, true, version, false)
if err != nil {
log.Fatalf("error: %s", err)
}
log.SetHandler(cli.Default)
if l, err := log.ParseLevel(args["--log-level"].(string)); err == nil {
log.SetLevel(l)
}
if args["help"].(bool) {
showHelp(args["<topic>"])
return
}
session := session.New(aws.NewConfig())
project := &project.Project{
Log: log.Log,
Path: ".",
}
if args["--dry-run"].(bool) {
log.SetLevel(log.WarnLevel)
project.Service = dryrun.New(session)
project.Concurrency = 1
} else {
project.Service = lambda.New(session)
}
if dir, ok := args["--chdir"].(string); ok {
if err := os.Chdir(dir); err != nil {
log.Fatalf("error: %s", err)
}
}
if err := project.Open(); err != nil {
log.Fatalf("error opening project: %s", err)
}
switch {
case args["list"].(bool):
list(project)
case args["deploy"].(bool):
deploy(project, args["<name>"].([]string), args["--env"].([]string))
case args["delete"].(bool):
delete(project, args["<name>"].([]string), args["--yes"].(bool))
case args["invoke"].(bool):
invoke(project, args["<name>"].([]string), args["--verbose"].(bool), args["--async"].(bool))
case args["rollback"].(bool):
rollback(project, args["<name>"].([]string), args["<version>"])
case args["build"].(bool):
build(project, args["<name>"].([]string))
case args["logs"].(bool):
tail(project, args["<name>"].([]string), args["--filter"].(string))
}
}
示例5: downloadReleaseAsset
func downloadReleaseAsset(r *github.ReleaseAsset, newName *string, newPath *string) {
var outDir string
if newPath == nil {
outDir = binDir()
} else {
outDir = *newPath
}
downloadUrlString := *r.BrowserDownloadURL
log.Infof("Downloading release asset: %s", downloadUrlString)
log.Infof("Copying to: %s", outDir)
downloadUrl, err := url.Parse(downloadUrlString)
if err != nil {
log.Fatalf("Error: Could not parse URL: %v", err)
}
var fileName string
if newName == nil {
_, fileName = path.Split(downloadUrl.Path)
} else {
fileName = *newName
}
outName := outDir + "/" + fileName
out, err := os.Create(outName)
if err != nil {
log.Fatalf("Error: Could not create local file: %v", err)
}
defer out.Close()
resp, err := http.Get(downloadUrlString)
if err != nil {
log.Fatalf("Error: Could not get remote file: %v", err)
}
defer resp.Body.Close()
bar := ioprogress.DrawTextFormatBar(20)
progressFunc := ioprogress.DrawTerminalf(os.Stdout, func(progress, total int64) string {
return fmt.Sprintf("%s %s %20s", fileName, bar(progress, total), ioprogress.DrawTextFormatBytes(progress, total))
})
progress := &ioprogress.Reader{
Reader: resp.Body,
Size: resp.ContentLength,
DrawInterval: time.Millisecond,
DrawFunc: progressFunc,
}
_, err = io.Copy(out, progress)
if err != nil {
log.Fatalf("Error: Could not copy local file: %v", err)
}
err = os.Chmod(outName, 0755)
if err != nil {
log.Fatalf("Error: Could not make %s executable. Try with (sudo)?", outName)
}
}
示例6: invokeCmdRun
// reads request json from stdin and outputs the responses
func invokeCmdRun(c *cobra.Command, args []string) {
lv := &invokeCmdLocalValues
dec := json.NewDecoder(os.Stdin)
kind := function.RequestResponse
if lv.Async {
kind = function.Event
}
err := pv.project.LoadFunctions(lv.name)
if err != nil {
log.Fatalf("error: %s", err)
return
}
fn := pv.project.Functions[0]
for {
var v map[string]interface{}
err := dec.Decode(&v)
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("error parsing response: %s", err)
}
var reply, logs io.Reader
if e, ok := v["event"].(map[string]interface{}); ok {
reply, logs, err = fn.Invoke(e, v["context"], kind)
} else {
reply, logs, err = fn.Invoke(v, nil, kind)
}
if err != nil {
log.Fatalf("error response: %s", err)
}
if lv.Logs {
io.Copy(os.Stderr, logs)
}
io.Copy(os.Stdout, reply)
fmt.Fprintf(os.Stdout, "\n")
}
}
示例7: build
// build outputs the generated archive to stdout.
func build(project *project.Project, name []string) {
fn, err := project.FunctionByName(name[0])
if err != nil {
log.Fatalf("error: %s", err)
}
zip, err := fn.Zip()
if err != nil {
log.Fatalf("error: %s", err)
}
_, err = io.Copy(os.Stdout, zip)
if err != nil {
log.Fatalf("error: %s", err)
}
}
示例8: main
func main() {
log.SetHandler(cli.Default)
if err := root.Command.Execute(); err != nil {
log.Fatalf("Error: %s", err)
}
}
示例9: main
func main() {
log.SetHandler(cli.Default)
args := os.Args[1:]
// Cobra does not (currently) allow us to pass flags for a sub-command
// as if they were arguments, so we inject -- here after the first TF command.
// TODO(tj): replace with a real solution and send PR to Cobra #251
if len(os.Args) > 1 && os.Args[1] == "infra" {
off := 1
out:
for i, a := range args {
for _, cmd := range tf {
if a == cmd {
off = i
break out
}
}
}
args = append(args[0:off], append([]string{"--"}, args[off:]...)...)
}
root.Command.SetArgs(args)
if err := root.Command.Execute(); err != nil {
log.Fatalf("Error: %s", err)
}
stats.Client.ConditionalFlush(500, 24*time.Hour)
}
示例10: binDir
func binDir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatalf("Error: No working directory")
}
log.Infof("GOOS: %s", runtime.GOOS)
switch runtime.GOOS {
case "darwin":
fallthrough
case "dragonfly":
fallthrough
case "linux":
fallthrough
case "freebsd":
fallthrough
case "netbsd":
fallthrough
case "openbsd":
dir = "/usr/local/bin"
break
default:
break
}
return dir
}
示例11: rollback
// rollback the function with optional version.
func rollback(project *project.Project, name []string, version interface{}) {
fn, err := project.FunctionByName(name[0])
if err != nil {
log.Fatalf("error: %s", err)
}
if version == nil {
err = fn.Rollback()
} else {
err = fn.RollbackVersion(version.(string))
}
if err != nil {
log.Fatalf("error: %s", err)
}
}
示例12: metricsCmdRun
func metricsCmdRun(c *cobra.Command, args []string) {
lv := &metricsCmdLocalValues
err := pv.project.LoadFunctions(lv.name)
if err != nil {
log.Fatalf("error: %s", err)
}
fn := pv.project.Functions[0]
d, err := time.ParseDuration(lv.duration)
if err != nil {
log.Fatalf("error: %s", err)
}
start := time.Now().UTC().Add(-d)
end := time.Now().UTC()
mc := &metrics.MetricCollector{
Metrics: []string{"Invocations", "Errors", "Duration", "Throttles"},
Collected: 0,
FunctionName: fn.FunctionName,
Service: cloudwatch.New(pv.session),
StartDate: start,
EndDate: end,
}
aggregated := make(map[string]aggregatedMetric)
for n := range mc.Collect() {
aggregated[n.Name] = aggregatedMetric{n.Name, aggregate(n.Value)}
}
println()
defer println()
for _, m := range aggregated {
switch m.Name {
case "Duration":
fmt.Printf(" \033[34m%11s:\033[0m %vms\n", m.Name, m.Count)
default:
fmt.Printf(" \033[34m%11s:\033[0m %v\n", m.Name, m.Count)
}
}
}
示例13: buildCmdRun
// outputs the generated archive to stdout
func buildCmdRun(c *cobra.Command, args []string) {
lv := &buildCmdLocalValues
fn, err := pv.project.FunctionByName(lv.name)
if err != nil {
log.Fatalf("error: %s", err)
}
zip, err := fn.Build()
if err != nil {
log.Fatalf("error: %s", err)
}
_, err = io.Copy(os.Stdout, zip)
if err != nil {
log.Fatalf("error: %s", err)
}
}
示例14: New
func New(network, raddr string, priority syslog.Priority, tag string) *Handler {
w, err := syslog.Dial(network, raddr, priority, tag)
if err != nil {
log.Fatalf("%v", err)
}
return &Handler{
w: w,
}
}
示例15: rollbackCmdRun
func rollbackCmdRun(c *cobra.Command, args []string) {
lv := &rollbackCmdLocalValues
fn, err := pv.project.FunctionByName(lv.name)
if err != nil {
log.Fatalf("error: %s", err)
}
if lv.version == "" {
err = fn.Rollback()
} else {
err = fn.RollbackVersion(lv.version)
}
if err != nil {
log.Fatalf("error: %s", err)
}
}