Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move examples to a separate repo to minimize dependencies #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harrisonhjones
Copy link
Contributor

Overview

As brought up in #16 this PR removes our examples (@jordic to move them to a new repo) to minimize the deps pulled into this project.

Testing

Pushed this change to my fork. Checked that the build succeeds in some cases: https://travis-ci.org/github/harrisonhjones/goics/builds/765948947 (build failures for 1.9 and 1.8 addressed in #17 )

@jordic
Copy link
Owner

jordic commented Apr 30, 2021

There's no need to an extra repo, just move them inside a examples folder. It's enough!

@harrisonhjones
Copy link
Contributor Author

Does that remove their deps from go.mod? If so I did not know that.

@harrisonhjones
Copy link
Contributor Author

Hey @jordic, checking in on this. Any thoughts?

@pivaldi
Copy link

pivaldi commented Jul 8, 2024

Hi,

Making a fresh install of this library, this load these unwanted libraries :

>  go mod graph | grep  goics
pi/essai github.com/jordic/[email protected]
github.com/jordic/[email protected] github.com/go-sql-driver/[email protected]
github.com/jordic/[email protected] github.com/gorilla/[email protected]
github.com/jordic/[email protected] github.com/jmoiron/[email protected]

I don't understand the need of mysql, gorilla and sqlx in the example, there is no need of these libs to provide a comprehensive example :

package main

import (
	"log"
	"net/http"
	"time"

	"github.com/jordic/goics"
)

const serverHost = "localhost:9000"

type Reserva struct {
	UID         string // Should be uuid.UUID from "github.com/google/uuid"
	DateStart   time.Time
	DataEnd     time.Time
	Location    string
	Summary     string
	Description string
}

// A collection of rous
type ReservasCollection []*Reserva

func main() {
	http.Handle("/", http.HandlerFunc(LimpiezaHandler))

	log.Print("Server started at http://" + serverHost)
	log.Fatal(http.ListenAndServe(serverHost, nil))
}

func LimpiezaHandler(w http.ResponseWriter, r *http.Request) {
	log.Print("Calendar request")
	// Setup headers for the calendar
	w.Header().Set("Content-type", "text/calendar")
	w.Header().Set("charset", "utf-8")
	w.Header().Set("Content-Disposition", "inline")
	w.Header().Set("filename", "calendar.ics")
	// Get the Collection models
	collection := GetReservas()
	// Encode it.
	goics.NewICalEncode(w).Encode(collection)
}

func GetReservas() ReservasCollection {
	now := time.Now()
	desc := `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin urna felis, porta in convallis cursus, eleifend ac orci…`

	return ReservasCollection{
		{
			UID:         "d4c8a472-2c06-4c95-929e-885e3db7ee51",
			DateStart:   now,
			DataEnd:     now.Add(time.Hour),
			Location:    "Here",
			Summary:     "This is the summary",
			Description: desc,
		},
		{
			UID:         "28aa46c7-f7d0-4727-bf5c-4e54b7a72bce",
			DateStart:   now.Add(26 * time.Hour),
			DataEnd:     now.Add(27 * time.Hour),
			Location:    "There",
			Summary:     "This is an other summary",
			Description: desc + " Bis…",
		},
	}
}

// We implement ICalEmiter interface that will return a goics.Componenter.
func (rc ReservasCollection) EmitICal() goics.Componenter {
	c := goics.NewComponent()
	c.SetType("VCALENDAR")
	c.AddProperty("CALSCAL", "GREGORIAN")
	c.AddProperty("PRODID;X-RICAL-TZSOURCE=TZINFO", "-//tmpo.io")

	for _, ev := range rc {
		s := goics.NewComponent()
		s.SetType("VEVENT")
		k, v := goics.FormatDateField("DTSTART", ev.DateStart)
		s.AddProperty(k, v)
		k, v = goics.FormatDateField("DTEND", ev.DataEnd)
		s.AddProperty(k, v)
		s.AddProperty("UID", ev.UID)
		s.AddProperty("DESCRIPTION", ev.Description)
		s.AddProperty("SUMMARY", ev.Summary)
		s.AddProperty("LOCATION", ev.Location)

		c.AddComponent(s)
	}

	return c
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants