nedpals / vex

Easy-to-use, modular web framework built for V
https://nedpals.github.io/vex
MIT License
340 stars 28 forks source link

Error "cannot register struct `nedpals.vex.ctx.Req`" #17

Closed icebob closed 3 years ago

icebob commented 3 years ago

Hi,

I've installed vex and trying it with a simple example code:

module main

import nedpals.vex.server
import nedpals.vex.ctx

fn main() {
    mut s := server.new()

    s.get('/greet/:name', fn (req ctx.Req, mut res ctx.Resp) {
        name := req.params['name']
        res.send('Hello, $name!', 200)
    })
    println('Starting server listening on port 5005...')
    s.serve(5005)
}

But when I try to run it I've got it:

cebob@ubuntu:~/work/moleculerjs/sidecar/examples/full/v$ v run demo-vex.v
/home/icebob/.vmodules/nedpals/vex/ctx/context.v:5:12: error: cannot register struct `nedpals.vex.ctx.Req`, another type with this name exists
    3 | import time
    4 | 
    5 | pub struct Req {
      |            ~~~
    6 | pub mut:
    7 |     body string

Could you help me? I'm using V 0.2 e4f94b6.

Thanks in advance!

harish2704 commented 3 years ago

@nedpals : Can you please specify the version ( hash ) of vlang on which the above mentioned db example will run successfully?

in a quick look, it seems like the vlang compiler fails to process duplicate import statements. Am I right?

alichraghi commented 3 years ago

This problem is with the v compiler and not the vex problem It will be solved soon

nedpals commented 3 years ago

@nedpals : Can you please specify the version ( hash ) of vlang on which the above mentioned db example will run successfully?

in a quick look, it seems like the vlang compiler fails to process duplicate import statements. Am I right?

Yes. I'll add a note to the readme today regarding that one

harish2704 commented 3 years ago

@icebob : Even though it is not an error from vex library, I tried a quick solution and it worked. The solution patch is given below.

diff --git a/router/router.v b/router/router.v
index 7431367..1c3532d 100644
--- a/router/router.v
+++ b/router/router.v
@@ -1,6 +1,6 @@
 module router

-import ctx
+import nedpals.vex.ctx
 import io
 import net.http
 import net.urllib
nedpals commented 3 years ago

@harish2704 no need for the workaround. it has been fixed already here: https://github.com/vlang/v/pull/7699