### Instruction:
Develop a Golang microservice that accepts HTTP requests containing JSON payloads representing geometric shapes (circle, rectangle, triangle) with their dimensions. The service should calculate the area and perimeter of the shape and store the results in a PostgreSQL database. Additionally, create an endpoint to retrieve the stored calculations.


### Response:

To develop the Golang microservice, we'll need to follow these steps:

1. Create a new Go project and import necessary packages.
2. Define data structures for geometric shapes and their dimensions.
3. Set up an HTTP server with endpoints for handling requests.
4. Implement functions to calculate area and perimeter of each shape.
5. Connect to a PostgreSQL database and create tables for storing calculations.
6. Add logic to store calculated results in the database.
7. Create an endpoint to retrieve stored calculations.

Here's a sample implementation:

```go
package main

import (
	"database/sql"
	"encoding/json"
	"fmt"
	"log"
	"math"
	"net/http"

	"github.com/gorilla/mux"
	_ "github.com/lib/pq"
)

type Shape struct {
	Type      string  `json:"type"`
	Radius    float64 `json:"radius,omitempty"`
	Width     float64 `json:"width,omitempty"`
	Height    float64 `json:"height,omitempty"`
	Base      float64 `json:"base,omitempty"`
	SideA     float64 `json:"side_a,omitempty"`
	SideB     float64 `json:"side_b,omitempty"`
	SideC     float64 `json:"side_c,omitempty"`
	Area      float64 `json:"-"`
	Perimeter float64 `json:"-"`
}

var db *sql.DB

func main() {
	var err error
	db, err = sql.Open("postgres", "user=your_user password=your_password dbname=shapes sslmode=disable")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	router := mux.NewRouter()
	router.HandleFunc("/calculate", CalculateHandler).Methods("POST")
	router.HandleFunc("/results", ResultsHandler).Methods("GET")

	log.Fatal(http.ListenAndServe(":8080", router))
}

func CalculateHandler(w http.ResponseWriter, r *http.Request) {
	var shape Shape
	err := json.NewDecoder(r.Body).Decode(&shape)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	switch shape.Type {
	case "circle":
		shape.Area = math.Pi * math.Pow(shape.Radius, 2)
		shape.Perimeter = 2 * math.Pi * shape.Radius
	case "rectangle":
		shape.Area = shape.Width * shape.Height
		shape.Perimeter = 2 * (shape.Width + shape.Height)
	case "triangle":
		s := (shape.SideA + shape.SideB + shape.SideC) / 2
		shape.Area = math.Sqrt(s * (s - shape.SideA) * (s - shape.SideB) * (s - shape.SideC))
		shape.Perimeter = shape.SideA + shape.SideB + shape.SideC
	default:
		http.Error(w, "Invalid shape type", http.StatusBadRequest)
		return
	}

	query := `INSERT INTO shapes (type, area, perimeter) VALUES ($1, $2, $3)`
	_, err = db.Exec(query, shape.Type, shape.Area, shape.Perimeter)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(shape)
}

func ResultsHandler(w http.ResponseWriter, r *http.Request) {
	rows, err := db.Query(`SELECT type, area, perimeter FROM shapes`)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer rows.Close()

	var results []Shape
	for rows.Next() {
		var shape Shape
		err := rows.Scan(&shape.Type, &shape.Area, &shape.Perimeter)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		results = append(results, shape)
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(results)
}
```

Before running the code, make sure to create a PostgreSQL database named `shapes` and replace the placeholders in the connection string with your actual credentials. You also need to create a table called `shapes`:

```sql
CREATE TABLE shapes (
    id SERIAL PRIMARY KEY,
    type VARCHAR(255) NOT NULL,
    area DOUBLE PRECISION NOT NULL,
    perimeter DOUBLE PRECISION NOT NULL
);
```

To test the microservice, you can send HTTP requests using tools like curl or Postman.

For example, to calculate the area and perimeter of a circle with radius 5:

```
curl -X POST -H "Content-Type: application/json" -d '{"type": "circle", "radius": 5}' http://localhost:8080/calculate
```

To retrieve stored calculations:

```
curl -X GET http://localhost:8080/results
```