This is my code:
func Login(w http.ResponseWriter, r *http.Request) {
fmt.Println("Login prccessing")
email := r.FormValue("email")
password := r.FormValue("password")
fmt.Println(email + password)
var netTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 50 * time.Second,
}).Dial,
TLSHandshakeTimeout: 50 * time.Second,
}
var netClient = &http.Client{
Timeout: time.Second * 50,
Transport: netTransport,
}
res, err := netClient.Get("https://account.sloppy.zone/accounts/" + email)
if err != nil {
fmt.Println(err.Error())
http.Redirect(w, r, "/", http.StatusSeeOther)
}
responeData, errs := ioutil.ReadAll(res.Body)
fmt.Println(string(responeData))
if errs != nil {
log.Fatal(errs)
}
var info LoginInfo
json.Unmarshal(responeData, &info)
if email == info.Id && password == info.Password {
http.Redirect(w, r, "/manager", http.StatusSeeOther)
} else {
http.Redirect(w, r, "/", http.StatusSeeOther)
}
}
I'm trying to run service containerized with docker and deploy it on a docker container host (sloppy.io) and this service call another service (account service) to get account and password from that service and verify them with user input at the same host.The problem is when I login to my page then 502 Bad Gateway show up.Track to log I see error:TLS handshake timeout.
How can I solve this?
are both services running on sloppy.io?
As your golang application depends on the account service, you should define this dependency in your setup and use docker’s networking features to connect both services. Doing so will also give you the ability to run an arbitrary number of instances as a docker swarm or inside another scalable cluster infrastructure like sloppy.io.
This also has the advantage that you do not need to expose your backend (account service) to the public.
You can either use docker-compose or sloppy.io's command line interface to build and run your application. Sloppy configuration files are quite similar to docker-compose.yml
files. See http://kb.sloppy.io/features/connecting-containers
Here is an example configuration as sloppy.yml
version: "v1"
project: "myproject"
services:
frontend:
golang_service:
dependencies:
- "../backend/account_service"
domain: "//my_golang_service.sloppy.zone"
env:
- ACCOUNT_HOST: "account_service.backend.myproject"
image: "dockerhub_username/golang_service:1.0.0"
port: 80
backend:
account_service:
image: "dockerhub_username/account_service:1.0.0"
This just covers the basic configuration. You will probably want to add volumes and environment variables. If you already have an existing docker-compose.yml, you can convert it to sloppy.yml using sloppose (github.com/sloppyio/sloppose).