Skip to content

This projects implements the EUR-Lex Web Service (Search) in Golang. For more information see README.md

License

Notifications You must be signed in to change notification settings

trevor87/eurlex-ws-go

 
 

Repository files navigation

eurlex-ws-go

Overview

eurlex-ws-go provides an implementation of the EUR-Lex Webservice (Search) in Go. The API is described here and here.

Install

go get -u github.com/slipke/eurlex-ws-go

Usage

Create a simple query and call the API (replace <username> and <password> with your credentials):

import (
    log "github.com/sirupsen/logrus"
	"github.com/slipke/eurlex-ws-go"
)

func main() {
	cfg := eurlex.NewConfig("<usename>", "<password>")
	ws := eurlex.NewWebservice(cfg)

	sr, err := ws.Search(
		eurlex.NewSearchRequestFromString("DN~32014R1338 OR DN~32014R1337"),
	)
	if err != nil {
		log.Fatalf("Failed to issue request: %s", err)
		return
	}

	log.Printf(
		"Returned %d elements (Page: %d, NumHits: %d, TotalHits: %d, Language: %s)",
		len(sr.Result),
		sr.Page,
		sr.NumHits,
		sr.TotalHits,
		sr.Language,
	)

	for _, r := range sr.Result {
		log.Printf("Result title: %s", r.Content.Notice.Expression.Title)
	}
}

Config

eurlex.Config is used to configure your webservice, it has the following defaults:

Config{
    ...
    Logger:   logrus.StandardLogger(),
    Client:   http.DefaultClient,
}

SearchRequest

eurlex.SearchRequest is used to to query the API.

It has the following defaults:

SearchRequest{
    Page:           1,
    PageSize:       10,
    SearchLanguage: "en",
}

Page defines the current page, whereas PageSize defines the maximum numbers of results in the response. SearchLanguage defines the language of the results.

SearchResult

The structure of the returned SearchResult is derived from the returning XML. An example can be found in fixtures/result.xml. More information can be found under Resources.

Resources

About

This projects implements the EUR-Lex Web Service (Search) in Golang. For more information see README.md

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.8%
  • Makefile 0.2%