Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs and add a validator tool for our api docs #850

Merged
merged 1 commit into from
Oct 27, 2017

Conversation

harshavardhana
Copy link
Member

No description provided.

@harshavardhana harshavardhana changed the title Fix docs and add a validator function for each of our docs. Fix docs and add a validator tool for our api docs Oct 19, 2017
exec.Command("gofmt", cmdArgs...).Run()

cmdArgs = []string{"-w", testFilePath}
exec.Command("goimports", cmdArgs...).Run()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation fails for FGetEncryptedObject, looks like encrypt is not getting imported

Failed to validate code at docs/API.md:18247

// Generate a master symmetric key
key := encrypt.NewSymmetricKey([]byte("my-secret-key-00"))

// Build the CBC encryption material
cbcMaterials, err := encrypt.NewCBCSecureMaterials(key)
if err != nil {
    fmt.Println(err)
    return
}

err = minioClient.FGetEncryptedObject("mybucket", "myobject", "/tmp/myobject", cbcMaterials)
if err != nil {
    fmt.Println(err)
    return
}

Copy link
Member Author

@harshavardhana harshavardhana Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It runs fine on CI looks like you have a local issue, goimports has a bug btw it stops scanning imports if it reaches a directory which it cannot access.

Go to the directory and check manually what is going on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goimports has a bug btw it stops scanning imports if it reaches a directory which it cannot access.

This is what I faced.

Go to the directory and check manually what is going on.

will do

fmt.Printf("Failed to validate code at %s:%d\n%s", docPath, p.Pos, p.Text)
os.Exit(255)
}
fmt.Printf("Successfully validated %s code at %s:%d\n", p.Lang, docPath, p.Pos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.Pos is a little confusing, not clear what position it is referring to

Successfully validated go code at docs/API.md:7695
Successfully validated go code at docs/API.md:8261
Successfully validated go code at docs/API.md:8847
Successfully validated go code at docs/API.md:9279
Successfully validated go code at docs/API.md:10467
Successfully validated go code at docs/API.md:11698
Successfully validated go code at docs/API.md:13270
Successfully validated go code at docs/API.md:14553
Successfully validated go code at docs/API.md:15424
Successfully validated go code at docs/API.md:16389
Successfully validated go code at docs/API.md:17463

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A position is the position in file with number of characters. It doesn't equate to line number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case, I dont feel it adds any value, can we remove it?

)

var templateMain = `
// +build ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text can be in separate file like checker.go.template

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor

@nitisht nitisht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and Tested

@harshavardhana
Copy link
Member Author

@balamurugana can you review this again?

@@ -0,0 +1,23 @@
// +build ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think this line can be removed.

  2. tpl extension is too limited. IMO we would have fully expanded .template

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot remove build ignore, it is needed to avoid conflicting with other packages in current directory .tpl is acceptable name most projects like hugo etc support this. We don't need to call it .template

@@ -0,0 +1,167 @@
// +build ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should build on make to ensure its compiling all the time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no make in minio-go, We ensure by running on travis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a make in minio-go

Name: "skip",
Value: 2,
Usage: "Skip entries before validating the code.",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would need to have a template like mc --help to show how this can be used with examples.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add that.

entryN++

cmdArgs := []string{"-s", "-w", "-l", testFilePath}
exec.Command("gofmt", cmdArgs...).Run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have a function or closure hide this logic here. This way you could have cmdArgs globally. If available I prefer long option than short option for readability (if available)

function runGofmt(string testFilePath) {
    ...
}

exec.Command("gofmt", cmdArgs...).Run()

cmdArgs = []string{"-w", testFilePath}
exec.Command("goimports", cmdArgs...).Run()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


// Go build current directory
cmdArgs = []string{"build", "-o", testBinPath, testFilePath}
if cerr := exec.Command("go", cmdArgs...).Run(); cerr != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

I think we don't need have args -o testBinPath. This intention here is to check whether testFilePath compiles are not.

Also we would need to show compilation error if any. This way we know what exact problem in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-o builds a binary with right name. Compilation error is displayed with the cerr.

@harshavardhana
Copy link
Member Author

Can you review this again Bala?

@harshavardhana
Copy link
Member Author

PR is updated @balamurugana please check.

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,17 @@
all: checks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants