dwr

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 13 Imported by: 0

README

go-dwr-client

Client Tests

go-dwr-client is a simple Direct Web Remoting Client (DWR) written in Go. This client can be used to communicate with DWR servers.

Beware that this project is a prototype, therefore expect bugs and breaking changes in the future.

Usage

package main

import (
	"log"

	"github.com/adrianmo/go-dwr-client"
)

func main() {
	baseParams := &dwr.Params{
		"callCount":  "1",
		"windowName": "foo",
		"instanceId": "1",
		"c0-id":      "0",
	}

	client, err := dwr.NewClient("https://example.com/vol", baseParams)
	if err != nil {
		log.Fatal(err)
	}

	extraParams := &dwr.Params{
		"c0-e1":     "string:87345",
		"c0-e2":     "string:X709183",
		"c0-param0": "Object_Object:{foo:reference:c0-e1, bar:reference:c0-e2}",
	}
	args := []string{"firstArg"}

	res, err := client.Request("/vol/info.do", "MySvcAjax", "getData", args, extraParams)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(res.Body)
}

Contributing

Issues and Pull Requests are welcomed and encouraged.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a Direct Web Remoting (DWR) client that manages communication with DWR endpoints.

func NewClient

func NewClient(baseURL string, baseParams *Params) (*Client, error)

NewClient returns a new DWR client.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client used by the DWR client.

func (*Client) Request

func (c *Client) Request(page, script, method string, args []string, extraParams *Params) (res *http.Response, err error)

Request formats and sends a DWR request (HTTP Post request) with the given DWR configuration. The parameters provided in extraParams will override any base parameter if there the key is already present.

func (*Client) SessionID

func (c *Client) SessionID() string

SessionID returns the current DWR session ID used by the client. Returns an empty string if the client has not been initialized.

type Params

type Params map[string]string

Params used for DWR requests.

func (*Params) String

func (p *Params) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL