Only pass State struct pointer to StateOpen, not entire response
This commit is contained in:
		
					parent
					
						
							
								44143c0c2d
							
						
					
				
			
			
				commit
				
					
						70b2e8069b
					
				
			
		
					 3 changed files with 10 additions and 8 deletions
				
			
		| 
						 | 
					@ -13,7 +13,7 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func StateOpen(
 | 
					func StateOpen(
 | 
				
			||||||
	authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
 | 
						authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
 | 
				
			||||||
	resp *types.SpaceAPIResponseV14,
 | 
						resp *types.SpaceState,
 | 
				
			||||||
) func(http.ResponseWriter, *http.Request) {
 | 
					) func(http.ResponseWriter, *http.Request) {
 | 
				
			||||||
	return func(w http.ResponseWriter, r *http.Request) {
 | 
						return func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		body := updateEndpointValidator(authDB, validCredentials, w, r)
 | 
							body := updateEndpointValidator(authDB, validCredentials, w, r)
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ func StateOpen(
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Set SpaceAPI response values
 | 
							// Set SpaceAPI response values
 | 
				
			||||||
		resp.State.Open = newState
 | 
							resp.Open = newState
 | 
				
			||||||
		resp.State.LastChange = time.Now().Unix()
 | 
							resp.LastChange = time.Now().Unix()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Respond with OK
 | 
							// Respond with OK
 | 
				
			||||||
		w.WriteHeader(http.StatusOK)
 | 
							w.WriteHeader(http.StatusOK)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
					@ -37,7 +37,7 @@ func main() {
 | 
				
			||||||
		handlers.Root(&conf.Response),
 | 
							handlers.Root(&conf.Response),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	http.HandleFunc("/state/open",
 | 
						http.HandleFunc("/state/open",
 | 
				
			||||||
		handlers.StateOpen(conf.Credentials, conf.Dynamic.State.Open.AllowedCredentials, &conf.Response),
 | 
							handlers.StateOpen(conf.Credentials, conf.Dynamic.State.Open.AllowedCredentials, &conf.Response.State),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	// Register handlers for Environmental Sensors
 | 
						// Register handlers for Environmental Sensors
 | 
				
			||||||
	for key, envSensorConfigs := range conf.Dynamic.Sensors {
 | 
						for key, envSensorConfigs := range conf.Dynamic.Sensors {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								types/v14.go
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								types/v14.go
									
										
									
									
									
								
							| 
						 | 
					@ -11,10 +11,7 @@ type SpaceAPIResponseV14 struct {
 | 
				
			||||||
		Lat     float64 `json:"lat"`
 | 
							Lat     float64 `json:"lat"`
 | 
				
			||||||
		Lon     float64 `json:"lon"`
 | 
							Lon     float64 `json:"lon"`
 | 
				
			||||||
	} `json:"location"`
 | 
						} `json:"location"`
 | 
				
			||||||
	State struct {
 | 
						State   SpaceState `json:"state"`
 | 
				
			||||||
		Open       bool  `json:"open"`
 | 
					 | 
				
			||||||
		LastChange int64 `json:"lastchange"`
 | 
					 | 
				
			||||||
	} `json:"state"`
 | 
					 | 
				
			||||||
	Contact struct {
 | 
						Contact struct {
 | 
				
			||||||
		Phone    string `json:"phone"`
 | 
							Phone    string `json:"phone"`
 | 
				
			||||||
		IRC      string `json:"irc"`
 | 
							IRC      string `json:"irc"`
 | 
				
			||||||
| 
						 | 
					@ -40,6 +37,11 @@ type SpaceAPIResponseV14 struct {
 | 
				
			||||||
	} `json:"links"`
 | 
						} `json:"links"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SpaceState struct {
 | 
				
			||||||
 | 
						Open       bool  `json:"open"`
 | 
				
			||||||
 | 
						LastChange int64 `json:"lastchange"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type EnvironmentSensor struct {
 | 
					type EnvironmentSensor struct {
 | 
				
			||||||
	Value       float64 `json:"value"`
 | 
						Value       float64 `json:"value"`
 | 
				
			||||||
	Unit        string  `json:"unit"`
 | 
						Unit        string  `json:"unit"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue