Skip to content

stagerightlabs/iago

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Iago CLI Tool

A command-line tool for making HTTP requests to third-party APIs with configurable API keys and settings. Built with Go for easy distribution and maintenance.

Features

  • πŸš€ Easy Distribution: Single binary with no dependencies
  • πŸ”§ Configurable: YAML-based configuration for API keys and settings
  • 🌐 HTTP Client: Built-in HTTP client with proper error handling
  • πŸ“ CLI Interface: Professional command-line interface using Cobra
  • πŸ”’ Secure: API key masking and secure configuration handling

Installation

Option 1: Download Pre-built Binary

Download the appropriate binary for your platform from the releases page and place it in your PATH.

Option 2: Build from Source

# Clone the repository
git clone <repository-url>
cd iago

# Build the binary
make build

# Or build for all platforms
make build-all

Quick Start

  1. First Run: The tool will create a default configuration file

    ./iago config
  2. Edit Configuration: Update config.yaml with your API settings

    api_key: "your-actual-api-key"
    base_url: "https://api.yourservice.com"
    timeout: 30
    user_agent: "iago-cli/1.0"
  3. Make API Requests:

    # GET request
    ./iago get /users
    
    # With verbose output
    ./iago get /users --verbose

Usage

Commands

# Show help
iago --help

# Test the tool
iago hello

# Show current configuration
iago config

# Make a GET request
iago get /endpoint

# Make requests with verbose output
iago get /endpoint --verbose

# Use custom config file
iago config --config /path/to/config.yaml

Configuration

The tool looks for configuration files in the following order:

  1. ./config.yaml (current directory)
  2. ./config.yml (current directory)
  3. ~/.iago.yaml (home directory)
  4. ~/.iago.yml (home directory)

Configuration Options

# Iago CLI Configuration
api_key: "your-api-key-here"           # Required: Your API key
base_url: "https://api.example.com"    # Required: Base URL for API requests
timeout: 30                            # Optional: Request timeout in seconds (default: 30)
user_agent: "iago-cli/1.0"            # Optional: User agent string

Development

Project Structure

iago/
β”œβ”€β”€ main.go              # Entry point
β”œβ”€β”€ go.mod              # Go module file
β”œβ”€β”€ config/
β”‚   └── config.go       # Configuration handling
β”œβ”€β”€ api/
β”‚   └── client.go       # HTTP client for API calls
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ root.go         # Root command and global flags
β”‚   β”œβ”€β”€ hello.go        # Hello command
β”‚   β”œβ”€β”€ config.go       # Config command
β”‚   └── get.go          # GET request command
β”œβ”€β”€ config.yaml         # Example config file
β”œβ”€β”€ Makefile            # Build system
└── README.md           # This file

Building

# Build for current platform
make build

# Build for all platforms
make build-all

# Run the application
make run

# Run tests
make test

# Format code
make fmt

# Clean build artifacts
make clean

Adding New Commands

  1. Create a new file in the cmd/ directory (e.g., cmd/post.go)
  2. Define your command using Cobra
  3. Add it to the root command in init()

Example:

package cmd

import (
    "github.com/spf13/cobra"
)

var postCmd = &cobra.Command{
    Use:   "post [path]",
    Short: "Make a POST request",
    Run: func(cmd *cobra.Command, args []string) {
        // Your command logic here
    },
}

func init() {
    rootCmd.AddCommand(postCmd)
}

Learning Go Concepts

This project demonstrates several important Go concepts:

1. Packages and Modules

  • go.mod defines the module
  • Each directory is a package
  • Import paths use the module name

2. Structs and Methods

type Client struct {
    config     *config.Config
    httpClient *http.Client
}

func (c *Client) MakeRequest(opts RequestOptions) (*APIResponse, error) {
    // Method implementation
}

3. Error Handling

resp, err := client.Get(path, nil)
if err != nil {
    fmt.Fprintf(os.Stderr, "Error: %v\n", err)
    os.Exit(1)
}

4. Interfaces

Go uses interfaces for polymorphism. The http.Client implements the Doer interface.

5. Pointers and References

func NewClient(cfg *config.Config) *Client {
    return &Client{
        config: cfg,
    }
}

6. Goroutines and Channels (for future async features)

// Example for future async requests
go func() {
    resp, err := client.Get(path, nil)
    // Handle response
}()

API Client Usage

The api.Client provides methods for making HTTP requests:

// Create a client
client := api.NewClient(config)

// Make a GET request
resp, err := client.Get("/users", nil)

// Make a POST request
data := map[string]interface{}{
    "name": "John Doe",
    "email": "john@example.com",
}
resp, err := client.Post("/users", data, nil)

// Handle the response
if resp.Success {
    fmt.Printf("Response: %+v\n", resp.Data)
} else {
    fmt.Printf("Error: %s\n", resp.Error)
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License.

Why "Iago"?

Iago is named after the character from Shakespeare's "Othello" - a master manipulator who orchestrates complex schemes. Just like Iago manipulates events in the play, this CLI tool helps you orchestrate API requests! 🎭

About

JIRA CLI Client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published