exsnake exsnake - 1 year ago 90
HTTP Question

HttpServer and Julia error with match method

I'm trying to understand how to work with this package for Julia.

Im using the following code (is an example from the package):

using HttpServer

function fibonacci(n)
if n == 1 return 1 end
if n == 2 return 1 end
prev = BigInt(1)
pprev = BigInt(1)
for i=3:n
curr = prev + pprev
pprev = prev
prev = curr
return prev

http = HttpHandler() do req::Request, res::Response
m = match(r"^/fibo/(\d+)/?$",req.resource)
if m == nothing
return Response(404)
number = BigInt(m.captures[1])
if number < 1 || number > 100_000
return Response(500)
return Response(string(fibonacci(number)))

http.events["error"] = (client, err) -> println(err)
http.events["listen"] = (port) -> println("Listening on $port...")

server = Server(http)
run(server, 8031)

And trying to access to the server with this link:


But i get the next error:


ERROR: MethodError: Cannot
an object of type
SubString{String} to an object of type BigInt

What im doing wrong?

I have problems to figure out what
does, maybe there is my problem...

Answer Source

You get this error because method BigInt(s::AbstractString) is deprecated and was remove in julia 0.5. Use number = parse(BigInt,m.captures[1]) instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download