Esempio n. 1
0
func TestCamelToSnake(t *testing.T) {
	try := func(camel, snake string) {
		if got := gas.ToSnake(camel); got != snake {
			t.Errorf("expected '%s', got '%s'", snake, got)
		}
	}
	for _, test := range []struct{ camel, snake string }{
		{"A", "a"},
		{"AId", "a_id"},
		{"MacBookPro", "mac_book_pro"},
		{"ABC", "abc"},
		{"OneTwoThreeFour", "one_two_three_four"},
		{"ServerURL", "server_url"},
		{"DLServerURL", "dl_server_url"},
		{"DlServerURL", "dl_server_url"},
		{"", ""},
	} {
		try(test.camel, test.snake)
	}
}
Esempio n. 2
0
File: models.go Progetto: moshee/gas
func newField(s reflect.StructField) (f *field) {
	f = new(field)
	f.t = s.Type
	f.originalName = gas.ToSnake(s.Name)
	if tag := s.Tag.Get("sql"); tag != "" {
		f.name = tag
	} else {
		f.name = f.originalName
	}

	// recursively register models
	m, err := Register(s.Type)
	if err != nil {
		// We don't return the error here because an error indicates that there
		// is no model (struct pointer) associated with f and we should just
		// continue on. f is just a regular value.
		return f
	}
	f.model = m
	return f
}