Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick start error #48

Open
qq516249940 opened this issue Jul 25, 2022 · 0 comments
Open

quick start error #48

qq516249940 opened this issue Jul 25, 2022 · 0 comments

Comments

@qq516249940
Copy link

qq516249940 commented Jul 25, 2022

go version: 1.18

package main

import (
	"crypto/tls"
	"fmt"
	"log"
	"net/http"

	"github.com/cavaliercoder/go-zabbix"
)

func main() {
	// Default approach - without session caching
	session, err := zabbix.NewSession("http://zabbix/api_jsonrpc.php", "Admin", "zabbix")
	if err != nil {
		panic(err)
	}

	version, err := session.GetVersion()

	if err != nil {
		panic(err)
	}

	fmt.Printf("Connected to Zabbix API v%s", version)

	// Use session builder with caching.
	// You can use own cache by implementing SessionAbstractCache interface
	// Optionally an http.Client can be passed to the builder, allowing to skip TLS verification,
	// pass proxy settings, etc.

	client := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true
			}
		}
	}

	cache := zabbix.NewSessionFileCache().SetFilePath("./zabbix_session")
	session, err := zabbix.CreateClient("http://zabbix/api_jsonrpc.php").
		WithCache(cache).
		WithHTTPClient(client).
		WithCredentials("Admin", "zabbix").
		Connect()
	if err != nil {
		log.Fatalf("%v\n", err)
	}

	version, err := session.GetVersion()

	if err != nil {
		log.Fatalf("%v\n", err)
	}

	fmt.Printf("Connected to Zabbix API v%s", version)
}

command-line-arguments

./main.go:35:29: syntax error: unexpected newline, expecting comma or }
./main.go:36:5: syntax error: unexpected newline, expecting comma or }
./main.go:37:4: syntax error: unexpected newline, expecting comma or }
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant