1
00:00:00,720 --> 00:00:06,540
So before we move on to server side form validation, I do want to take a little pause here and just

2
00:00:06,540 --> 00:00:11,280
implement some refactoring and refactoring just means moving things around inside your project.

3
00:00:12,000 --> 00:00:16,410
So if you look at our project structure right now, we have a command folder that has a web folder that

4
00:00:16,410 --> 00:00:22,200
has the three files that establish our main routine, set up our middleware and our routine, and that's

5
00:00:22,200 --> 00:00:22,620
fine.

6
00:00:22,650 --> 00:00:25,700
That's a conventional way to build a Web application and go.

7
00:00:26,190 --> 00:00:32,580
Then we have this package, this package folder, and inside of that we have config handlers, models

8
00:00:32,580 --> 00:00:33,150
and render.

9
00:00:33,150 --> 00:00:34,980
And that's fine because those are packages.

10
00:00:35,760 --> 00:00:39,540
But conventionally and there is no hard and fast rule for this.

11
00:00:39,540 --> 00:00:46,980
But conventionally, when you set up a project, anything in your package pkg folder is it means something

12
00:00:46,980 --> 00:00:48,390
to people that are looking at your code.

13
00:00:48,390 --> 00:00:54,840
It means these are resources that are completely divorced from the logic of your application and that

14
00:00:54,840 --> 00:00:57,570
I can import into my own application.

15
00:00:57,660 --> 00:00:58,720
And that's not the case here.

16
00:00:59,190 --> 00:01:05,970
So, for example, this config that's only useful in our application, it depends upon a particular

17
00:01:05,970 --> 00:01:06,900
session manager.

18
00:01:06,900 --> 00:01:10,050
It has a structure that's of use to nobody except ourselves.

19
00:01:10,500 --> 00:01:17,310
In the same way, obviously, our handlers are set up specifically for our application and so are our

20
00:01:17,310 --> 00:01:19,030
models and so is our rendering engine.

21
00:01:19,590 --> 00:01:22,350
So what I'm going to do is refactor.

22
00:01:22,350 --> 00:01:28,410
I'm going to create a new directory here right at the root level of my application, and I'm going to

23
00:01:28,410 --> 00:01:29,370
call it internal.

24
00:01:31,230 --> 00:01:34,170
And that is where I'm going to move these packages.

25
00:01:34,380 --> 00:01:38,880
So I'm going to it's going to be I'm going to take advantage of refactoring built into my application.

26
00:01:39,120 --> 00:01:44,760
I'm going to select these three packages and I'm going to move them to internal those four packages,

27
00:01:44,760 --> 00:01:46,440
I guess, and move them to internal.

28
00:01:46,800 --> 00:01:52,590
And a little dialog pops up in my idee that says, are you sure you want to move these specified directories

29
00:01:52,590 --> 00:01:53,640
from there to here?

30
00:01:54,060 --> 00:01:55,710
And I'm going to check this box.

31
00:01:55,710 --> 00:01:59,820
If it's not checked, check her references and that will do some of the heavy lifting for me.

32
00:01:59,820 --> 00:02:00,810
So I'll refactor it.

33
00:02:02,310 --> 00:02:07,950
So when I do that, things are going to break almost certainly if I try to run this application right

34
00:02:07,950 --> 00:02:14,970
now, go run command Web Maime or Stargirl, chances are there's going to be an error.

35
00:02:15,060 --> 00:02:15,560
Maybe not.

36
00:02:15,570 --> 00:02:16,350
We'll find out here.

37
00:02:16,380 --> 00:02:17,280
Look, it just started.

38
00:02:17,370 --> 00:02:18,530
That worked beautifully.

39
00:02:18,540 --> 00:02:18,930
All right?

40
00:02:18,930 --> 00:02:23,130
So I'll stop the application and let's look at some of the things that have changed.

41
00:02:23,640 --> 00:02:24,990
So back to my main package.

42
00:02:24,990 --> 00:02:25,820
Anything changed there?

43
00:02:25,830 --> 00:02:26,340
Yes.

44
00:02:26,370 --> 00:02:30,030
Notice how it changed GitHub, dotcom, teszler bookings.

45
00:02:30,030 --> 00:02:31,650
This used to say pkg.

46
00:02:31,650 --> 00:02:36,300
And if yours doesn't, you need to change it to pkg from pkg to internal.

47
00:02:37,050 --> 00:02:40,950
So change those for us in the Roots folder under the imports.

48
00:02:41,310 --> 00:02:42,000
Same thing.

49
00:02:42,000 --> 00:02:42,780
And went to internal.

50
00:02:42,780 --> 00:02:49,860
And this makes more sense and it makes more sense because these packages are all internal to my application.

51
00:02:50,400 --> 00:02:55,380
Now if I write something and I will later on in the course, probably if I write something that other

52
00:02:55,380 --> 00:02:57,690
people can use, I'll stick that in the package folder.

53
00:02:57,720 --> 00:02:59,160
So that wasn't too hard.

54
00:02:59,610 --> 00:03:03,840
If your idea did not add automatically refactor things for you, just run it.

55
00:03:03,960 --> 00:03:06,600
It'll tell you where the errors are and go change your imports.

56
00:03:06,600 --> 00:03:08,670
And that's pretty much all you have to do.

57
00:03:08,670 --> 00:03:13,320
And that's one of the great advantages of using an integrated development environment like Goaland.

58
00:03:13,320 --> 00:03:20,700
And there's similar functionality in visual studio code or jet brains, intelligence of the public edition

59
00:03:20,940 --> 00:03:22,050
or the community edition.

60
00:03:22,230 --> 00:03:25,650
Most I.D. support refactoring out of the box.

61
00:03:25,680 --> 00:03:31,050
So I'm going to commit these changes and push them up to get so refactored

62
00:03:33,270 --> 00:03:34,800
to use internal.

63
00:03:36,530 --> 00:03:38,930
Packages and push.

64
00:03:42,150 --> 00:03:46,450
And we are good, so I shall commit push and it's all set.

65
00:03:46,950 --> 00:03:52,080
All right, now in the next lecture, we'll move on to doing some server side form validation, which

66
00:03:52,080 --> 00:03:54,210
is utterly critical, as you will see shortly.
