LoginSignup
0
0

More than 3 years have passed since last update.

V言語でWeb Serverを立てる(失敗)

Posted at

前回の続き

導入

前回とほぼ一緒ですが、コンパイル方法が少し変わっています。
compilerフォルダが無くなっています。

kajiken@kajiken:~$ docker run --rm -it ubuntu
root@5ec2d954e645:/# apt-get update
root@5ec2d954e645:/# apt-get install vim git make curl gcc -y
root@5ec2d954e645:/#
root@5ec2d954e645:/# git clone https://github.com/vlang/v
root@5ec2d954e645:/# cd v
root@5ec2d954e645:/v# make
rm -rf vc/
git clone --depth 1 --quiet https://github.com/vlang/vc
#cp fns.h vc/fns.h
rm -rf /var/tmp/tcc/
git clone --depth 1 --quiet https://github.com/vlang/tccbin /var/tmp/tcc
cc -std=gnu11 -w -o v vc/v.c  -lm
rm -rf vc/
V has been successfully built
root@5ec2d954e645:/v# ln -s /v/v /usr/local/bin/v
root@5ec2d954e645:/v# cd
root@5ec2d954e645:~#
root@5ec2d954e645:~# echo println\(\'Hello World\'\) > hello.v
root@5ec2d954e645:~# v hello.v 
root@5ec2d954e645:~# ll hello
-rwxr-xr-x 1 root root 67920 Nov 11 0:15 hello*
root@5ec2d954e645:~# ./hello 
Hello World
root@5ec2d954e645:~# v run hello.v 
Hello World
root@5ec2d954e645:~# v --version
V 0.1.22 730ef96
root@5ec2d954e645:~#

Web Serverを立てる?

さて前回はまだ未実装だったPowerful built-in web frameworkを使ってみましょう。
ただ、まだプレアルファ版らしいです。

まずは公式サイトにある以下から。

Powerful built-in web framework

['/post/:id']
fn (b Blog) show_post(id int) vweb.Result {
  post := b.posts_repo.retrieve(id) or {
     return vweb.not_found()
  }
  return vweb.view(post)
}

openssl/ssl.hが無いと言われたのでapt-get install libssl-dev -yで入れてやる。

root@ed72e8337897:/# v run web.v 
warning: web.v:1:6: the following imports were never used: 
 * vweb
/web.tmp.c:175:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
V error: C error. This should never happen. 
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
root@ed72e8337897:/#
root@ed72e8337897:/# apt-get install libssl-dev -y

再チャレ。

root@ed72e8337897:/# v web.v 
check()
next token = `]`
web.v:3:13: expected `name` but got `'/post/:id'`
    1| import vweb
    2| 
    3| ['/post/:id']
                   ^
    4| fn (b Blog) show_post(id int) vweb.Result {
    5|   post := b.posts_repo.retrieve(id) or {
root@ed72e8337897:/#

ふぁっ!?
ちょっとまって、え、まって。

…アノテーションもどきな['/post/:id']はまだ使えなさそう。
vorumのソースを見るとTODOコメントになっている。

気を取り直してvorumを真似てみる。

web.v
import vweb

struct App {
}

fn main() {
  mut app := App{}
  vweb.run(app, 8092)
}
root@ed72e8337897:~# v web.v 
check()
next token = `eof`
V panic: array.get: index out of range (i == 429, a.len == 27)
addr2line: 'v': No such file
v(+0x35f5) [0x55fd6829b5f5]
addr2line: 'v': No such file
v(+0x2300) [0x55fd6829a300]
addr2line: 'v': No such file
v(+0x168e2) [0x55fd682ae8e2]
addr2line: 'v': No such file
v(+0x16804) [0x55fd682ae804]
addr2line: 'v': No such file
v(+0x43ae9) [0x55fd682dbae9]
addr2line: 'v': No such file
v(+0x44ff9) [0x55fd682dcff9]
addr2line: 'v': No such file
v(+0x44e7a) [0x55fd682dce7a]
addr2line: 'v': No such file
v(+0x2bd9a) [0x55fd682c3d9a]
addr2line: 'v': No such file
v(+0x282ca) [0x55fd682c02ca]
addr2line: 'v': No such file
v(+0x255a9) [0x55fd682bd5a9]
addr2line: 'v': No such file
v(+0x1e1ba) [0x55fd682b61ba]
addr2line: 'v': No such file
v(+0x20053) [0x55fd682b8053]
addr2line: 'v': No such file
v(+0x1fa9b) [0x55fd682b7a9b]
addr2line: 'v': No such file
v(+0x1f362) [0x55fd682b7362]
addr2line: 'v': No such file
v(+0x4bb24) [0x55fd682e3b24]
addr2line: 'v': No such file
v(+0x1e504) [0x55fd682b6504]
addr2line: 'v': No such file
v(+0x1c73d) [0x55fd682b473d]
addr2line: 'v': No such file
v(+0x1c455) [0x55fd682b4455]
addr2line: 'v': No such file
v(+0x45887) [0x55fd682dd887]
addr2line: 'v': No such file
v(+0x44f39) [0x55fd682dcf39]
addr2line: 'v': No such file
v(+0x23a7d) [0x55fd682bba7d]
addr2line: 'v': No such file
v(+0x4197d) [0x55fd682d997d]
addr2line: 'v': No such file
v(+0x343db) [0x55fd682cc3db]
addr2line: 'v': No such file
v(+0x34a30) [0x55fd682cca30]
addr2line: 'v': No such file
v(+0x677f7) [0x55fd682ff7f7]
addr2line: 'v': No such file
v(+0x68ff9) [0x55fd68300ff9]
??:0:                                         | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7f53b60a0b97]
addr2line: 'v': No such file
v(+0x193a) [0x55fd6829993a]
root@ed72e8337897:~#

…なんじゃこりゃあ。

落ち着け、まだ慌てるような時間ではない。
動いているやつがあるならそれを動かせば良いではないか。

root@ed72e8337897:/# git clone https://github.com/vlang/vorum
root@ed72e8337897:/# cd vorum/
root@ed72e8337897:/vorum# v .
check()
next token = `$`
./_user.v:12:12: expected `name` but got `'
                select name from users 
                where id='`
   10|  users := app.db.exec_param('
   11|          select name from users 
   12|          where id=$user_id and random_id=$1', random_id)
                           ^
   13|  if users.len == 0 {
   14|          return error('no such user "$user_id" r="$random_id"')
root@ed72e8337897:/vorum#

なんですと!?

オチ

https://github.com/vlang/vorum/issues/9
v 0.1.19から動かない…っておーい!

もう少し暖かく見守ろう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0