package main import ( "net/http" "time" ) // Rewards needs a comment func Rewards(w http.ResponseWriter, r *http.Request) { type data struct { Title string Uploaded bool Success bool Rewards rewards CumulativeRewards map[time.Month]string Colors []string Currency string ErrorText string Lending bool } // set common attributes d := data{} // set title according to site that called this function switch r.URL.Path { case "/rewards": d.Title = "Cake" case "/kraken": d.Title = "Kraken" } // check the method used to access this site (GET/POST) switch r.Method { case http.MethodGet: // display upload site d.Uploaded = false d.Success = false render(w, "rewards.html", d) case http.MethodPost: // upload the file that was posted here var success bool = false lines, err := uploadFile(w, r) if err == nil { success = true } else { // set ErrorText d.ErrorText = err.Error() } // prepare data for usage var color string var currency string var precision int var rewards rewards if success == true { currency = lines[1].Cryptocurrency color, precision, d.Lending = getCurrencyOpts(currency) rewards = monthlyRewardOverview(lines) d.CumulativeRewards = getCumulative(rewards, precision) d.Success = success d.Rewards.Staking = rewards.Staking d.Rewards.Confectionery = rewards.Confectionery d.Rewards.Lapis = rewards.Lapis d.Rewards.LapisDFI = rewards.LapisDFI d.Rewards.Referral = rewards.Referral d.Rewards.Airdrop = rewards.Airdrop d.Rewards.Swapped = rewards.Swapped d.Colors = getOtherColors(color, 8) d.Currency = currency } d.Uploaded = true render(w, "rewards.html", d) } // create a new line instance }