Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nurse committed Nov 8, 2015
0 parents commit 6b827c9
Show file tree
Hide file tree
Showing 12 changed files with 736 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.swp
*.o
*.a
mkmf.log
gohttp.h
gohttp.so
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (C) 2015 NARUSE, Yui. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Gohttp

A demo to implement a extension library with Go.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'gohttp'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install gohttp

## Usage

```ruby
require 'gohttp'
r = Gohttp.get('https://example.com/index.html')
puts r.body.read
```

## Contributing

1. Fork it ( https://github.com/nurse/gohttp/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
18 changes: 18 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
require 'rake/extensiontask'

RSpec::Core::RakeTask.new(:spec)
task :default => [:compile, :spec]

spec = eval File.read('gohttp.gemspec')
Rake::ExtensionTask.new('gohttp', spec) do |ext|
ext.ext_dir = 'ext/gohttp'
ext.lib_dir = File.join(*['lib', 'gohttp', ENV['FAT_DIR']].compact)
ext.source_pattern = "*.{c,cpp,go}"
end

RSpec::Core::RakeTask.new :spec do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end
18 changes: 18 additions & 0 deletions ext/gohttp/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'mkmf'
find_executable('go')
$objs = []
def $objs.empty?; false ;end
create_makefile("gohttp/gohttp")
case `#{CONFIG['CC']} --version`
when /Free Software Foundation/
ldflags = '-Wl,--unresolved-symbols=ignore-all'
when /clang/
ldflags = '-undefined dynamic_lookup'
end
File.open('Makefile', 'a') do |f|
f.write <<eom.gsub(/^ {8}/, "\t")
$(DLLIB): Makefile $(srcdir)/gohttp.go $(srcdir)/wrapper.go
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' \
go build -p 4 -buildmode=c-shared -o $(DLLIB) $(srcdir)/gohttp.go $(srcdir)/wrapper.go
eom
end
Loading

0 comments on commit 6b827c9

Please sign in to comment.