Skip to main content

Go Examples for adaline.report

Go code examples for the Adaline Report API using the standard library.

All examples use the Go standard library (net/http, encoding/json, mime/multipart). No external dependencies required.

Setup

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"mime/multipart"
	"net/http"
	"os"
	"path/filepath"
)

const (
	baseURL = "https://api.adaline.report"
	apiKey  = "your-api-key"
)

func apiRequest(method, path string, body io.Reader) (*http.Response, error) {
	req, err := http.NewRequest(method, baseURL+path, body)
	if err != nil {
		return nil, err
	}
	req.Header.Set("X-API-Key", apiKey)
	if body != nil && method != "GET" {
		req.Header.Set("Content-Type", "application/json")
	}
	return http.DefaultClient.Do(req)
}

Scan a Document

func scanDocument(filePath string) (map[string]interface{}, error) {
	file, err := os.Open(filePath)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	var buf bytes.Buffer
	writer := multipart.NewWriter(&buf)
	part, err := writer.CreateFormFile("file", filepath.Base(filePath))
	if err != nil {
		return nil, err
	}
	io.Copy(part, file)
	writer.Close()

	req, err := http.NewRequest("POST", baseURL+"/api/v1/scan", &buf)
	if err != nil {
		return nil, err
	}
	req.Header.Set("X-API-Key", apiKey)
	req.Header.Set("Content-Type", writer.FormDataContentType())

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	return result, nil
}

func main() {
	result, err := scanDocument("syllabus.pdf")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Printf("Score: %.1f%% (Grade %s)\n",
		result["overall_score"], result["grade"])
}

List Reports

func listReports(page int) (map[string]interface{}, error) {
	path := fmt.Sprintf("/api/v1/reports?page=%d", page)
	resp, err := apiRequest("GET", path, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	return result, nil
}

Get Report

func getReport(reportID string) (map[string]interface{}, error) {
	resp, err := apiRequest("GET", "/api/v1/reports/"+reportID, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	return result, nil
}

Create a Tag

func createTag(name, color string) (map[string]interface{}, error) {
	body, _ := json.Marshal(map[string]string{
		"name":  name,
		"color": color,
	})
	resp, err := apiRequest("POST", "/api/v1/tags", bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	return result, nil
}

Tag a Report

func tagReport(tagID, reportID string) error {
	path := fmt.Sprintf("/api/v1/tags/%s/reports/%s", tagID, reportID)
	resp, err := apiRequest("POST", path, nil)
	if err != nil {
		return err
	}
	resp.Body.Close()
	return nil
}

Share a Report

func shareReport(reportID string) (map[string]interface{}, error) {
	resp, err := apiRequest("POST", "/api/v1/reports/"+reportID+"/share", nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)
	return result, nil
}

Batch Scan

func batchScan(dir string) {
	entries, _ := os.ReadDir(dir)
	for _, entry := range entries {
		ext := filepath.Ext(entry.Name())
		if ext != ".pdf" && ext != ".docx" && ext != ".pptx" {
			continue
		}
		fmt.Printf("Scanning %s...\n", entry.Name())
		result, err := scanDocument(filepath.Join(dir, entry.Name()))
		if err != nil {
			fmt.Printf("  Error: %v\n", err)
			continue
		}
		fmt.Printf("  Score: %.1f%% (%s)\n",
			result["overall_score"], result["grade"])
	}
}
© 2026 Adaline LLC