Languages: English | ็ฎไฝไธญๆ
A comprehensive Go library for working with CWE (Common Weakness Enumeration) data, featuring API clients, rate limiting, tree operations, and more.
๐ Complete Documentation & API Reference
The complete documentation includes:
- API Reference - Detailed documentation for all types, functions, and methods
- Examples - Practical usage examples and tutorials
- Getting Started Guide - Quick start and basic usage
go get github.com/scagogogo/cwe
package main
import (
"fmt"
"log"
"github.com/scagogogo/cwe"
)
func main() {
// Create API client
client := cwe.NewAPIClient()
// Get CWE version
version, err := client.GetVersion()
if err != nil {
log.Fatal(err)
}
fmt.Printf("CWE Version: %s\n", version.Version)
// Fetch a weakness
weakness, err := client.GetWeakness("79")
if err != nil {
log.Fatal(err)
}
fmt.Printf("CWE-79: %s\n", weakness.Name)
}
- Complete CWE API Client - Full REST API client for CWE data access
- Rate Limiting - Built-in rate limiting to prevent API overload
- Tree Operations - Build and traverse CWE hierarchical structures
- Search & Filter - Powerful search capabilities for finding specific CWEs
- Data Management - Registry system for managing CWE collections
- Export/Import - JSON and XML serialization support
- Thread Safe - All components designed for concurrent usage
- Comprehensive Testing - 92.6% test coverage
The codebase is organized into focused modules for better maintainability:
cwe.go
- Package documentation and exported interfacescwe_model.go
- CWE data structures and methodscwe_registry.go
- CWE registry managementcwe_search.go
- Search functionalitycwe_utils.go
- Utility functions
api_client.go
- Base API client structureapi_client_version.go
- Version-related APIsapi_client_cwe.go
- CWE data retrieval APIsapi_client_relations.go
- Relationship query APIsapi_integration.go
- Integration features
http_client.go
- Rate-limited HTTP clientrate_limiter.go
- Rate limiting implementationdata_fetcher_utils.go
- Data fetching utilities
For comprehensive documentation and examples, visit our Documentation Website:
- API Reference - Complete API documentation
- Examples - Practical usage examples:
- Basic Usage - Getting started
- Fetching CWE Data - Data retrieval
- Building Trees - Hierarchical structures
- Search & Filter - Finding CWEs
- Export & Import - Data persistence
- Rate Limited Client - Advanced HTTP usage
# Clone the repository
git clone https://github.com/scagogogo/cwe.git
cd cwe
# Run examples
go run examples/01_basic_usage/main.go
go run examples/02_fetch_cwe/main.go
go run examples/03_build_tree/main.go
# Or use the example runner
go run examples/run_examples.go basic_usage
Comprehensive test suite with 92.6% coverage:
cwe_test.go
- CWE model basic functionalitycwe_registry_test.go
- Registry functionalitycwe_search_test.go
- Search functionalitycwe_utils_test.go
- Utility functions
api_client_test.go
- API client basic functionalityapi_client_cwe_test.go
- CWE data APIsapi_client_relations_test.go
- Relationship query APIsapi_client_version_test.go
- Version APIsapi_integration_test.go
- Integration features
build_tree_test.go
- Tree buildingfetch_category_test.go
- Category fetchingfetch_multiple_test.go
- Batch operationsxml_json_test.go
- Serialization
The library includes a sophisticated rate-limited HTTP client to prevent API overload and ensure reliable requests.
By default, the API client uses:
- 1 request per 10 seconds
- 3 retry attempts on failure
- 1 second retry interval
- 30 second HTTP timeout
import (
"time"
"net/http"
"github.com/scagogogo/cwe"
)
// Create a custom rate limiter (1 request per 2 seconds)
limiter := cwe.NewHTTPRateLimiter(2 * time.Second)
// Create client with custom rate limiting
client := cwe.NewAPIClientWithOptions("", 30*time.Second, limiter)
// All API requests will automatically respect rate limits
version, err := client.GetVersion()
weakness, err := client.GetWeakness("79")
// Get current rate limiter
limiter := client.GetRateLimiter()
// Adjust rate limit to 5 seconds per request
limiter.SetInterval(5 * time.Second)
// Or set a completely new rate limiter
newLimiter := cwe.NewHTTPRateLimiter(1 * time.Second)
client.SetRateLimiter(newLimiter)
// Build a hierarchical tree from a CWE view
tree, err := cwe.BuildCWETreeWithView(client, "1000")
if err != nil {
log.Fatal(err)
}
// Traverse the tree
tree.Walk(func(node *cwe.TreeNode) {
fmt.Printf("CWE-%s: %s\n", node.CWE.ID, node.CWE.Name)
})
// Create a registry and add CWEs
registry := cwe.NewCWERegistry()
registry.AddCWE(&cwe.CWEWeakness{ID: "79", Name: "Cross-site Scripting"})
// Search by keyword
results := registry.SearchByKeyword("script")
for _, result := range results {
fmt.Printf("Found: %s\n", result.Name)
}
# Run all tests
go test -v ./...
# Run tests with coverage
go test -v -cover ./...
# Run specific test
go test -v -run TestAPIClient
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
# Clone the repository
git clone https://github.com/scagogogo/cwe.git
cd cwe
# Install dependencies
go mod download
# Run tests
go test -v ./...
# Run examples
go run examples/01_basic_usage/main.go
This project is licensed under the MIT License - see the LICENSE file for details.
- MITRE CWE for providing the CWE data and API
- The Go community for excellent libraries and tools
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions