Table of contents
Part of nurago, a collection of independent Go packages for backend services.
import "github.com/tecnickcom/nurago/pkg/jirasrv"
Package jirasrv provides a typed HTTP client foundation for Jira Server REST integrations.
It wraps low-level HTTP plumbing in a Client and exposes a generic request
entry point (Client.SendRequest) along with typed Jira data models for common
payloads (issues, transitions, comments, users, visibility, properties,
metadata).
Core responsibilities handled by the client:
- API base-path composition (
/rest/api/2) - bearer-token authentication headers
- JSON request encoding and content headers
- request payload validation
- method-aware HTTP retry behavior
- connection and service health probing via
Client.HealthCheck
The client supports dependency injection and runtime tuning via options:
- custom HTTP transport/client (
WithHTTPClient) - request and ping timeouts (
WithTimeout,WithPingTimeout) - retry policy controls (
WithRetryAttempts,WithRetryDelay)
Reference
Jira Server REST API reference:
When To Use
- A service reads or updates Jira issues.
- You want authentication, retries, and encoding handled, while choosing the endpoint yourself.
Example
// A stand-in for a Jira Server instance. Real code passes the Jira base
// address and a personal access token.
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL.Path, r.URL.RawQuery)
fmt.Println("auth:", r.Header.Get("Authorization"))
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"key":"PROJ-42","fields":{"summary":"login fails"}}`))
}))
defer srv.Close()
client, err := jirasrv.New(srv.URL, "personal-access-token")
if err != nil {
fmt.Println(err)
return
}
query := url.Values{}
query.Set("fields", "summary")
// SendRequest covers any Jira REST endpoint, so the package does not
// have to model the whole API surface.
resp, err := client.SendRequest(
context.TODO(),
http.MethodGet,
"/issue/PROJ-42",
&query,
nil,
)
if err != nil {
fmt.Println(err)
return
}
// The base path (/rest/api/2) is applied by the client, so endpoints are
// given relative to it. The caller owns the response body.
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(resp.Body)
var issue struct {
Key string `json:"key"`
Fields struct {
Summary string `json:"summary"`
} `json:"fields"`
}
err = json.Unmarshal(body, &issue)
fmt.Println(issue.Key, issue.Fields.Summary, err)
// Output:
// GET /rest/api/2/issue/PROJ-42 fields=summary
// auth: Bearer personal-access-token
// PROJ-42 login fails <nil>
Full source is in example_jirasrv_test.go. More runnable examples are on pkg.go.dev.
Dependencies
Importing this package pulls 9 external modules:
github.com/gabriel-vasile/mimetypegithub.com/go-playground/localesgithub.com/go-playground/universal-translatorgithub.com/go-playground/validator/v10github.com/julienschmidt/httproutergithub.com/leodido/go-urngolang.org/x/cryptogolang.org/x/sysgolang.org/x/text