golint 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b17a8fc7941117aa55eb791c0701d08024bdaf88
4
+ data.tar.gz: 9a32b26e1bf0441e3c1dcc0e9bd8df8103dfe4b3
5
+ SHA512:
6
+ metadata.gz: 33db5a4cbdfa7db1140aa11fc409d866bc2ccf710cb10b2c1ca6a71046cd442bd8c935c5aca3989092bc359b8c20d6a9be25c06e28532d85fd2322398bcdedc4
7
+ data.tar.gz: 50f1567b999ad19b6806f9bf07f91c9683f93d93cd534f30f731124c279549abf8cb0f4cc1cd860ea5fe824482939a8c251218b4c92960ed7dfb7d7fece6944f
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gofmt-rb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kir Shatrov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Golint-rb
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ First of all, get `golint` package:
8
+
9
+ ```
10
+ go get github.com/golang/lint/golint
11
+ ```
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'golint'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install golint
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ matches = Golint.lint("some of your go code")
29
+ matches.each do |m|
30
+ puts m.line
31
+ puts m.comment
32
+ end
33
+ ```
34
+
35
+ ``
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/gofmt-rb/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.warning = true
8
+ t.verbose = true
9
+ end
10
+
data/golint.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'golint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "golint"
8
+ spec.version = Golint::VERSION
9
+ spec.authors = ["Kir Shatrov"]
10
+ spec.email = ["shatrov@me.com"]
11
+ spec.summary = %q{Ruby wrapper for golint utility}
12
+ spec.description = %q{Ruby wrapper for golint utility}
13
+ spec.homepage = "https://github.com/kirs/golint-rb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/golint.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "golint/version"
2
+ require "tempfile"
3
+ require "base64"
4
+
5
+ module Golint
6
+ class Match < Struct.new(:line, :comment)
7
+ end
8
+
9
+ class << self
10
+ REGEXP = /([\d]*):([\d]*):([\s\S]*)$/
11
+
12
+ def lint(content)
13
+ code = Base64.encode64(content).strip[0..16]
14
+ file = Tempfile.new(code)
15
+ file.write(content)
16
+ file.close
17
+
18
+ diff = `golint #{file.path}`
19
+
20
+ pattern = "#{file.path}:"
21
+
22
+ matches = []
23
+ diff.each_line do |line|
24
+ line = line.sub(pattern, "").sub("\n", "")
25
+ res = line.match(REGEXP)
26
+ matches << Match.new(res[1], res[3].strip)
27
+ end
28
+
29
+ matches
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Golint
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,147 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/base64"
5
+ "encoding/json"
6
+ "flag"
7
+ "fmt"
8
+ "io/ioutil"
9
+ "log"
10
+ "net/http"
11
+ "strconv"
12
+
13
+ "github.com/coopernurse/gorp"
14
+ "github.com/gorilla/mux"
15
+ _ "github.com/lib/pq"
16
+ )
17
+
18
+ var databaseConfigPath, envName, bindAddress string
19
+
20
+ func helloHandler(w http.ResponseWriter, req *http.Request) {
21
+ http.Redirect(w, req, "http://github.com", http.StatusFound)
22
+ }
23
+
24
+ func fetchItemHandler(w http.ResponseWriter, req *http.Request) {
25
+ vars := mux.Vars(req)
26
+ req.ParseForm()
27
+
28
+ force := len(req.FormValue("force")) > 0 && req.UserAgent() == secret_useragent
29
+
30
+ item_id := vars["item_id"]
31
+ if item_id != "" {
32
+ var some_item SomeItem
33
+ var err error
34
+
35
+ if !force {
36
+ err = dbmap.SelectOne(&some_item, "select id from caches where item_id=$1 limit 1", item_id)
37
+
38
+ log.Printf("found id: %d, %s", some_item.Id, err)
39
+ if err == nil {
40
+ respondWithJson(w, &some_item)
41
+ return
42
+ }
43
+ }
44
+
45
+ some_item, err = FetchSomeItem(item_id)
46
+ if err != nil {
47
+ log.Println(err)
48
+ http.Error(w, fmt.Sprintf("%s", err), 422)
49
+ return
50
+ }
51
+
52
+ if force {
53
+ log.Println("force fetch, removing cached item")
54
+ dbmap.Exec("delete from some_items_cache where item_id=$1", item_id)
55
+ }
56
+
57
+ err = dbmap.Insert(&some_item)
58
+ if err != nil {
59
+ log.Printf("insert error: %s", err)
60
+ }
61
+
62
+ respondWithJson(w, &some_item)
63
+ } else {
64
+ http.Error(w, "", 404)
65
+ }
66
+ }
67
+
68
+ func revisionHandler(w http.ResponseWriter, req *http.Request) {
69
+ revision_file := "/home/some/some/current/REVISION"
70
+
71
+ response, err := ioutil.ReadFile(revision_file)
72
+ if err != nil {
73
+ log.Printf("failed to read %s: %s", revision_file, err)
74
+ }
75
+
76
+ w.Write(response)
77
+ }
78
+
79
+ func searchHandler(w http.ResponseWriter, req *http.Request) {
80
+ req.ParseForm()
81
+
82
+ query := req.Form.Get("query")
83
+ category_id := req.Form.Get("category_id")
84
+ aspect_filters := BuildAspects(req.Form["aspects[][name]"], req.Form["aspects[][value]"])
85
+
86
+ if query != "" || category_id != "" {
87
+ per_page, err := strconv.ParseInt(req.Form.Get("per_page"), 10, 64)
88
+ if err != nil {
89
+ per_page = 10
90
+ }
91
+
92
+ page_num, err := strconv.ParseInt(req.Form.Get("page"), 10, 64)
93
+ if err != nil {
94
+ page_num = 1
95
+ }
96
+
97
+ search_result, err := SearchSomeItems(query, category_id, aspect_filters, per_page, page_num)
98
+ if err != nil {
99
+ fmt.Println(err)
100
+ http.Error(w, fmt.Sprintf("%s", err), 422)
101
+ return
102
+ }
103
+
104
+ // replace with respond json
105
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
106
+
107
+ b, err := json.Marshal(search_result)
108
+ if err != nil {
109
+ panic(err)
110
+ }
111
+
112
+ w.Write(b)
113
+ }
114
+ }
115
+
116
+ var (
117
+ dbmap *gorp.DbMap
118
+ secret_useragent string
119
+ )
120
+
121
+ const (
122
+ ROUTE_PREFIX = "/api"
123
+ )
124
+
125
+ func main() {
126
+ flag.Parse()
127
+
128
+ dbmap = initDb()
129
+ defer dbmap.Db.Close()
130
+
131
+ useragent := []byte("SomeItemSyncer")
132
+ secret_useragent = base64.StdEncoding.EncodeToString(useragent)
133
+
134
+ r := mux.NewRouter()
135
+ r.HandleFunc(fmt.Sprintf("%s/", ROUTE_PREFIX), helloHandler)
136
+ r.HandleFunc(fmt.Sprintf("%s/revision", ROUTE_PREFIX), revisionHandler)
137
+ r.HandleFunc(fmt.Sprintf("%s/items/{item_id}", ROUTE_PREFIX), fetchItemHandler)
138
+ r.HandleFunc(fmt.Sprintf("%s/search", ROUTE_PREFIX), searchHandler)
139
+ http.Handle("/", r)
140
+
141
+ fmt.Printf("Starting API on %s\n", bindAddress)
142
+
143
+ err := http.ListenAndServe(bindAddress, r)
144
+ if err != nil {
145
+ log.Fatalf("Server start error: %v", err)
146
+ }
147
+ }
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class TestGolint < MiniTest::Unit::TestCase
4
+ def test_shit
5
+ file = File.open('test/fixtures/server.go')
6
+ puts Golint.lint(file.read)
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+
15
+ require 'minitest/autorun'
16
+ require 'golint'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: golint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kir Shatrov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby wrapper for golint utility
42
+ email:
43
+ - shatrov@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - golint.gemspec
54
+ - lib/golint.rb
55
+ - lib/golint/version.rb
56
+ - test/fixtures/server.go
57
+ - test/golint_test.rb
58
+ - test/test_helper.rb
59
+ homepage: https://github.com/kirs/golint-rb
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Ruby wrapper for golint utility
83
+ test_files:
84
+ - test/fixtures/server.go
85
+ - test/golint_test.rb
86
+ - test/test_helper.rb
87
+ has_rdoc: