Skip to content

Commit

Permalink
Fix lint warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
errcw committed May 17, 2014
1 parent 1e069d3 commit 8068ef5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 117 deletions.
8 changes: 4 additions & 4 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type svnEntry struct {
const maxRequests = 10

// DownloadSvnDir reads an SVN XML directory index and downloads all the listed (filtered) files
func DownloadSvnDir(svnDirUrl string, filter *regexp.Regexp, outDir string) error {
response, err := http.Get(svnDirUrl)
func DownloadSvnDir(svnDirURL string, filter *regexp.Regexp, outDir string) error {
response, err := http.Get(svnDirURL)
if err != nil {
return err
}
Expand All @@ -34,15 +34,15 @@ func DownloadSvnDir(svnDirUrl string, filter *regexp.Regexp, outDir string) erro
return err
}

var downloadErr error = nil
var downloadErr error

wg := new(sync.WaitGroup)
c := make(chan int, maxRequests)
for _, e := range index.Entries {
if filter.MatchString(e.Name) {
c <- 1
wg.Add(1)
url := svnDirUrl + "/" + e.Name
url := svnDirURL + "/" + e.Name
file := filepath.Join(outDir, e.Name)
go func(url, file string) {
defer wg.Done()
Expand Down
19 changes: 1 addition & 18 deletions enums.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
package main

import "sort"

// An enumerated value.
type Enum struct {
Name string // Raw specification name
GoName string // Go name with the API prefix stripped
Value string // Raw specification value
}

type Enums map[string]*Enum
type SortedEnums []*Enum

func (f SortedEnums) Len() int { return len(f) }
func (f SortedEnums) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
func (f SortedEnums) Less(i, j int) bool { return f[i].Name < f[j].Name }

func (es Enums) Sort() SortedEnums {
sortedEnums := make(SortedEnums, 0, len(es))
for _, e := range es {
sortedEnums = append(sortedEnums, e)
}
sort.Sort(sortedEnums)
return sortedEnums
}
24 changes: 21 additions & 3 deletions functions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

// A Function.
import "fmt"

// A Function definition.
type Function struct {
Name string // C name of the function
GoName string // Go name of the function with the API prefix stripped
Expand All @@ -16,10 +18,26 @@ type Parameter struct {

// CName returns a C-safe parameter name.
func (p Parameter) CName() string {
return RenameIfReservedCWord(p.Name)
return renameIfReservedCWord(p.Name)
}

// GoName returns a Go-safe parameter name.
func (p Parameter) GoName() string {
return RenameIfReservedGoWord(p.Name)
return renameIfReservedGoWord(p.Name)
}

func renameIfReservedCWord(word string) string {
switch word {
case "near", "far":
return fmt.Sprintf("x%s", word)
}
return word
}

func renameIfReservedGoWord(word string) string {
switch word {
case "func", "type", "struct", "range", "map", "string":
return fmt.Sprintf("x%s", word)
}
return word
}
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func generate(name string, args []string) {
generated := false
for _, spec := range specs {
if spec.HasPackage(pkgSpec) {
log.Println("Generating package", pkgSpec.Api, pkgSpec.Version)
log.Println("Generating package", pkgSpec.API, pkgSpec.Version)
if err := spec.ToPackage(pkgSpec).GeneratePackage(); err != nil {
log.Fatal("Error generating package:", err)
}
Expand All @@ -91,27 +91,27 @@ func generate(name string, args []string) {
}

type PackageSpec struct {
Api string
API string
Version Version
}

func (pkgSpec PackageSpec) String() string {
return fmt.Sprintf("%s %s", pkgSpec.Api, pkgSpec.Version)
return fmt.Sprintf("%s %s", pkgSpec.API, pkgSpec.Version)
}

func parsePackageSpecs(specStrs string, specs []*Specification) ([]PackageSpec, error) {
pkgSpecs := make([]PackageSpec, 0)
if specStrs == "all" {
for _, spec := range specs {
for _, feature := range spec.Features {
pkgSpecs = append(pkgSpecs, PackageSpec{feature.Api, feature.Version})
pkgSpecs = append(pkgSpecs, PackageSpec{feature.API, feature.Version})
}
}
} else {
for _, specStr := range strings.Split(specStrs, ",") {
apiVersion := strings.Split(specStr, "@")
if len(apiVersion) != 2 {
return nil, fmt.Errorf("Error parsing generation specification:", specStr)
return nil, fmt.Errorf("error parsing generation specification:", specStr)
}
api := apiVersion[0]
version, err := ParseVersion(apiVersion[1])
Expand Down
7 changes: 4 additions & 3 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
// A Package holds the typedef, function, and enum definitions for a Go package.
type Package struct {
Name string
Api string
API string
Version Version
Typedefs []*Typedef
Enums map[string]Enum
Functions map[string]PackageFunction
}

// A PackageFunction is a package-specific Function wrapper.
type PackageFunction struct {
Function Function
Required bool
Expand All @@ -25,7 +26,7 @@ type PackageFunction struct {

// GeneratePackage writes a Go package file.
func (pkg *Package) GeneratePackage() error {
dir := filepath.Join(pkg.Api, pkg.Version.String(), pkg.Name)
dir := filepath.Join(pkg.API, pkg.Version.String(), pkg.Name)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
Expand Down Expand Up @@ -54,7 +55,7 @@ func (pkg *Package) Extensions() []string {
}
}
extensions := make([]string, 0, len(extensionSet))
for extension, _ := range extensionSet {
for extension := range extensionSet {
extensions = append(extensions, extension)
}
return extensions
Expand Down
Loading

0 comments on commit 8068ef5

Please sign in to comment.