Skip to content

SmartContractSecurity/SWC-registry-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Golang SWC Registry Library

CircleCI coverage Go Report Card Go Doc

This package aims to make the Smart Contract Weakness Classification (SWC) Registry accessible in Golang. To get an overview over the available methods, please check the Go Doc for this repo here.

Example

package main

import (
    swc "github.com/SmartContractSecurity/SWC-registry-go/pkg"
    "fmt"
)


func main() {
    s, err := swc.GetSWC("SWC-101")
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(s.GetMarkdown())
    }
}

Behaviour

On first use of the GetSWC function, the SWC registry is initialized from the SWC classification repository if it's not filled already. Further queries are then relayed to the already downloaded dataset - unless an update is triggered explicitly by the user.

There are two ways to update the internal SWC registry: from a local file or a remote URL. The user will have to get the package's SWC registry instance (a singleton and thread-safe) and call one of the update methods:

Update from URL

r := GetRegistry()
err := r.UpdateRegistryFromURL()
if err != nil {
    t.Fatalf("Loading from URL failed. Got error %s", err)
}

Alternatively, a custom URL can be passed. Otherwise we will default to the JSON file in the official SWC Registry repo: Also contained as DefaultGithubURL in the package.

Update from File

r := GetRegistry()
err := r.UpdateRegistryFromFile()
if err != nil {
    t.Fatalf("Loading from file failed. Got error %s", err)
}

This works analogously to the above example and defaults to DefaultFilePath unless given another valid file path to a JSON file.

About

Go library for accessing SWC-registry content

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages