在本地为Nativescript移动应用程序开发Golang后端

时间:2018-04-13 23:36:46

标签: angular go localhost nativescript

我正在使用Nativescript移动应用程序,同时尝试设计Golang后端。我没有实际部署后端的经验,所以现在我只想尝试在本地开发。所以我在我的模拟应用程序上有一些按钮:

import { Http } from "@angular/http"                                                                

+@Component({...}
+export class LoginComponent implements OnInit {...}{

    . . .

    // <Button ... (tap)="get_test()"></Button> 
    public get_test(){                                                                              
        this.http.get("http://localhost:8080/");                                                    
    }                                                                                               

}  

我从golang website复制的小型网络服务器:

 package main

 import (
     "log"
     "net/http"
 )

 func handler(w http.ResponseWriter, r *http.Request) {
     print("recieved")
 }

 func main() {
     http.HandleFunc("/", handler)
     log.Fatal(http.ListenAndServe(":8080", nil))
 }

我启动了go&#34;服务器&#34;:

go build main.go
./main

现在我的想法是,通过单击按钮,命令行应打印出recieved,我可以使用它来设计我的请求。但任何一方都没有发生任何事情代码中可能存在大量错误,我甚至不确定您是否可以在本地模拟这些错误。但任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

您的服务器端代码没有任何问题。这听起来像是(a)您的前端代码实际上没有触发http请求(您应该能够通过附加到浏览器的调试器来检测)或(b)您的前端正在尝试发出请求但是没有'我知道如何找到服务器(即网络问题)。